Frequency of the gene expression in Seurat

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)

enter image description here


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
))

Read more here: Source link