I am analysing my single cell RNA seq data with the Seurat package. I want to know if there is a possibilty to obtain the percentage expression of a list of genes per identity class, as actual numbers (e.g. a matrix) which I can write out to say an excel file. For example I want to be able to say gene X is expressed in 30% of cell A, 10% of cell B etc.

I can generate something comparable with:

DotPlot(object = my_object, genes.plot = "my_gene")

However the results are only graphic and I wish to have further processible numbers.


AverageExpression(object, genes.use = "my_gene")

Produces expression values which I cannot transform to percentages.

I will be very grateful on any hints.

  • $\begingroup$ Did you read the tutorials of seurat? Why you cannot transform to percentage expression values? $\endgroup$
    – llrs
    Commented Feb 15, 2019 at 8:49
  • $\begingroup$ @IIrs I will be very grateful for any hint. I am not able to figure a way how I can convert expression values for one cell type into percentage expression for that cell type. To say X% of my cell type C expresses this gene G. $\endgroup$
    – Charles
    Commented Feb 15, 2019 at 9:21

3 Answers 3


This can be solved like this:


my_genes <- c("gene1", "gene2", "gene3")

exp <- FetchData(object, my_genes)

matrix <- as.matrix(colMeans(exp  > 0))*100
  • 1
    $\begingroup$ Glad you found your way! Perhaps explaining how did you find this solution (what did you look up and where) will help your future self or other people in the same situation. Also are you sure that FetchData retrieve the expession data? (Also which one, the raw data, the scaled data or the imputed data?) $\endgroup$
    – llrs
    Commented Feb 15, 2019 at 11:18

You can get the table that is used to make the dot plot if you modify the DotPlot function to return it instead of the ggplot, and use the argument do.return=T.

To edit the function, the command is:


Then replace the last line "return(p)" by "return(data.to.plot)" and save the edit.

You can call the function and store the return in a variable.

The editing doesn't affect the source code, so the function will be untouched at your next R session.



Also potentially useful is the solution proposed here: https://github.com/satijalab/seurat/issues/1888

Basically, save DotPlot to an object, and your percentages are found within.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.