I have 2151 cells, I clustered them by Seurat to 5 clusters. With the code below, I am able to have the number of cells per cluster and per condition:

number_perCluster<- table([email protected]$conditions, 
                          [email protected]$clusterID)

Could I please get a hint on how I could proceed to produce a figure where I say: X% of cells treated with condition "Y" are located in cluster "C" and so forth?

Thank you in advance.

  • $\begingroup$ Have a look at prop.table, also if you want a figure, please describe it a bit more. This is usually better displayed as a table or heatmap, but perhaps you want something else... $\endgroup$
    – llrs
    Feb 6, 2019 at 13:39
  • $\begingroup$ Please don't also create a github issue on the Seurat page each time you ask a question here, there is no need $\endgroup$
    – TimStuart
    Feb 6, 2019 at 14:40

1 Answer 1


Here is a solution using dplyr and ggplot2:


meta.data <- pbmc_small[[]]

# create random classifications for the sake of this example
meta.data$condition <- sample(c('A', 'B', 'C'), nrow(meta.data), replace = TRUE)

counts <- group_by(meta.data, condition, res.1) %>% summarise(count = n())

ggplot(counts, aes(res.1, count, fill = condition)) +
  geom_bar(stat = 'identity')

enter image description here


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.