Answers.Body: <p>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.</p>
  
  <p>To edit the function, the command is:</p>
  
  <pre><code>trace("DotPlot",edit=TRUE)
  </code></pre>
  
  <p>Then replace the last line "return(p)" by "return(data.to.plot)" and save the edit.</p>
  
  <p>You can call the function and store the return in a variable.</p>
  
  <p>The editing doesn't affect the source code, so the function will be untouched at your next R session.</p>
  
  <p>Best,</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-15T21:42:56.900Z
Answers.LastActivityDate: 2019-03-15T21:42:56.900Z
Answers.UserDisplayName: Hicham Affia
Answers.Body: <p>Also potentially useful is the solution proposed here: <a href="https://github.com/satijalab/seurat/issues/1888" rel="nofollow noreferrer">https://github.com/satijalab/seurat/issues/1888</a></p>
  
  <p>Basically, save DotPlot to an object, and your percentages are found within. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-02T06:49:41.693Z
Answers.LastActivityDate: 2020-04-02T06:49:41.693Z
Answers.UserDisplayName: David Garfield
Answers.Body: <p>This can be solved like this:</p>
  
  <pre><code>library(Seurat)
  
  my_genes &lt;- c("gene1", "gene2", "gene3")
  
  exp &lt;- FetchData(object, my_genes)
  
  matrix &lt;- as.matrix(colMeans(exp  &gt; 0))*100
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-15T11:18:28.317Z
Answers.Text: 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?)
Answers.UserDisplayName: llrs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-15T10:40:25.197Z
Answers.LastActivityDate: 2019-02-15T11:08:30.890Z
Answers.LastEditDate: 2019-02-15T11:08:30.890Z
Answers.UserDisplayName: Charles
Body: <p>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.</p>
  
  <p>I can generate something comparable with:</p>
  
  <pre><code>DotPlot(object = my_object, genes.plot = "my_gene")
  </code></pre>
  
  <p>However the results are only graphic and I wish to have further processible numbers. </p>
  
  <p>Furthermore:</p>
  
  <pre><code>AverageExpression(object, genes.use = "my_gene")
  </code></pre>
  
  <p>Produces expression values which I cannot transform to percentages.</p>
  
  <p>I will be very grateful on any hints.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-15T08:49:41.757Z
Comments.Text: Did you read the tutorials of [seurat](https://satijalab.org/seurat/)? Why you cannot transform to percentage expression values?
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-15T09:21:38.413Z
Comments.Text: @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.
Comments.UserDisplayName: Charles
Tags: <r><scrnaseq><seurat>
Title: How can I obtain the percentage gene expression per identity class in Seurat as further processible numbers (e.g. matrix)?
ThreadText: # How can I obtain the percentage gene expression per identity class in Seurat as further processible numbers (e.g. matrix)?
  
  (Asked by: username_0 on 2019-02-14)
  
  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.
  
  Furthermore:
  
  ```
  AverageExpression(object, genes.use = "my_gene")
  
  ```
  
  Produces expression values which I cannot transform to percentages.
  
  I will be very grateful on any hints.
  
  **Tags:** r, scrnaseq, seurat
  
  > **Comments:**
  > **username_1**: Did you read the tutorials of [seurat](https://satijalab.org/seurat/)? Why you cannot transform to percentage expression values?  
  > **username_0**: @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.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2019-02-15. Score: 5 | Accepted answer
  
  This can be solved like this:
  
  ```
  library(Seurat)
  
  my_genes <- c("gene1", "gene2", "gene3")
  
  exp <- FetchData(object, my_genes)
  
  matrix <- as.matrix(colMeans(exp  > 0))*100
  
  ```
  
  > **Comments:**
  > **username_1**: 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?)  
  
  ---
  
  ### Answer by username_2 on 2019-03-15. Score: 3
  
  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:
  
  ```
  trace("DotPlot",edit=TRUE)
  
  ```
  
  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.
  
  Best,
  
  
  ---
  
  ### Answer by username_3 on 2020-04-02. Score: 1
  
  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.
  
  
  ---
  
  