Answers.Body: <pre><code>pt &lt;- table(Idents(myobj), myobj<span class="math-container">$orig.ident)
  pt &lt;- as.data.frame(pt)
  pt$</span>Var1 &lt;- as.character(pt$Var1)
  
  ggplot(pt, aes(x = Var2, y = Freq, fill = Var1)) +
    theme_bw(base_size = 15) +
    geom_col(position = "fill", width = 0.5) +
    xlab("Sample") +
    ylab("Proportion") +
    scale_fill_manual(values = brewer.pal(12, "Paired")) +
    theme(legend.title = element_blank())
  </code></pre>
  
  <p>This shall work. <code>myobj</code> is your seurat object. This is my old code so if I remember correct, <code>orig.ident</code> is your treated and untreated conditions. <code>Idents</code> should give you cell clusters.
  If this does not work, please let me know</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-23T20:00:09.653Z
Answers.LastActivityDate: 2020-03-23T20:00:09.653Z
Answers.UserDisplayName: Phoenix Mu
Answers.Body: <p>You can access these data from a Seurat object as columns of <code>object@meta.data</code> and tabulate them.</p>
  <p>There are functions such as “propellor” which will also implement this:</p>
  <p><a href="https://github.com/Oshlack/speckle" rel="nofollow noreferrer">https://github.com/Oshlack/speckle</a></p>
  <p>Note that a Seurat vignette also explores this topic:</p>
  <p><a href="https://satijalab.org/seurat/archive/v3.0/interaction_vignette.html" rel="nofollow noreferrer">https://satijalab.org/seurat/archive/v3.0/interaction_vignette.html</a></p>
  <p>You need to be careful when doing this to ensure different proportions are biological as single cell data is prone to technical errors.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-20T12:41:43.390Z
Answers.LastActivityDate: 2021-04-20T12:41:43.390Z
Answers.UserDisplayName: Tom Kelly ケリー・トム
Body: <p>I am using Seurat to analyze my single cell data. I have 2 conditions, treated and untreated.  I am trying to create a stacked bar graph in order to show the differences in cell types for each condition but need to collect the percentages of each cluster for the specific cell types. How to I put together a sheet that contains the percentages of each cluster and the make a stacked bar graph of comparison of each condition. </p>
  
Tags: <r><scrnaseq><seurat>
Title: Percentage of each cluster in Seurat
ThreadText: # Percentage of each cluster in Seurat
  
  (Asked by: username_0 on 2020-01-15)
  
  I am using Seurat to analyze my single cell data. I have 2 conditions, treated and untreated. I am trying to create a stacked bar graph in order to show the differences in cell types for each condition but need to collect the percentages of each cluster for the specific cell types. How to I put together a sheet that contains the percentages of each cluster and the make a stacked bar graph of comparison of each condition.
  
  **Tags:** r, scrnaseq, seurat
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-03-23. Score: 2
  
  ```
  pt <- table(Idents(myobj), myobj$orig.ident)
  pt <- as.data.frame(pt)
  pt$Var1 <- as.character(pt$Var1)
  
  ggplot(pt, aes(x = Var2, y = Freq, fill = Var1)) +
    theme_bw(base_size = 15) +
    geom_col(position = "fill", width = 0.5) +
    xlab("Sample") +
    ylab("Proportion") +
    scale_fill_manual(values = brewer.pal(12, "Paired")) +
    theme(legend.title = element_blank())
  
  ```
  
  This shall work. `myobj` is your seurat object. This is my old code so if I remember correct, `orig.ident` is your treated and untreated conditions. `Idents` should give you cell clusters.
  If this does not work, please let me know
  
  
  ---
  
  ### Answer by username_2 on 2021-04-20. Score: 1
  
  You can access these data from a Seurat object as columns of `object@meta.data` and tabulate them.
  
  There are functions such as “propellor” which will also implement this:
  
  <https://github.com/Oshlack/speckle>
  
  Note that a Seurat vignette also explores this topic:
  
  <https://satijalab.org/seurat/archive/v3.0/interaction_vignette.html>
  
  You need to be careful when doing this to ensure different proportions are biological as single cell data is prone to technical errors.
  
  
  ---
  
  