DotPlot
computes the fraction of cells expressing a gene in each group (metadata column), so you can cheat a little and extract the results from it [source].
library("Seurat")
features <- c("PECAM1", "CD14")
group_column <- "clusters"
perc_exp <- DotPlot(seu, features=features, group.by=group_column)$data[, c("features.plot", "id", "pct.exp")]
The returned data will look something like this:
> perc_exp
features.plot id pct.exp
1 PECAM1 Endothelial 26.55087
2 CD14 Endothelial 37.21239
3 PECAM1 T Cells 57.28534
4 CD14 T Cells 90.82078
You can then plot this easily using ggplot.
library("ggplot")
ggplot(perc_exp, aes(x=id, y=pct.exp, fill=id)) +
geom_col() +
facet_wrap(~features.plot)
Example data used.
perc_exp <- structure(list(features.plot = c("PECAM1", "CD14", "PECAM1",
"CD14"), id = c("Endothelial", "Endothelial", "T Cells", "T Cells"
), pct.exp = c(26.55086631421, 37.212389963679, 57.2853363351896,
90.8207789994776)), class = "data.frame", row.names = c(NA, -4L
))
By frequency do you mean the percent of cells in a cluster with at least one UMI detected for that gene?
Hello rpolicastro,
Yes. You are right!
Thank you!
Best,
Yue