Home > Community > Seurat VlnPlot presenting expression of multiple genes in a single cluster
Upvote

25

Downvote
+ Rstudio
+ R
+ Bioinformatics
Posted by
Ju Long

Seurat VlnPlot presenting expression of multiple genes in a single cluster

Diane Fiorito  Follow

To do so one workaround it to have your data in "long format" and then use the column that holds the "gene names" as the x variable while plotting.

You can use FetchData() to extract data from a Seurat object. VlnPlot's default is the data slot (of the active assay if using Seurat v3 I suppose). And you can specify which cells and genes to retrieve.

selected_cells <- names(panc8$celltype[panc8$celltype == "gamma"])data <- FetchData(panc8,                    vars = c('FZD9','CTNNB1','APC'),                    cells = selected_cells ,                    slot = "data")> head(data)           FZD9   CTNNB1      APCD101_5        0 0.000000 0.000000D101_43       0 2.007853 1.001958D101_93       0 0.000000 0.000000

Melt() would transform your data into "long format". By not specifying any arguments, we push for all of the info in the three variables to be gathered in two columns:

long_data <- melt(data)No id variables; using all as measure variables> head(long_data)  variable value1     FZD9     02     FZD9     03     FZD9     0> tail(long_data)     variable value1870      APC     01871      APC     01872      APC     0

ggplot2 is used to add "violin" and "jitter" layers. You can customize the output to look (exactly) like the VlnPlot() output.

ggplot(long_data,       aes(x = variable, y = value)) +  geom_violin() +  geom_jitter(size = 0.1)

enter image description here

And here is the same graph generated by VlnPlot():

enter image description here

There are no "violins" as the counts are almost entirely zeros. And see how different the ranges are in the y axes of the VlnPlot. So the "tweak" I have presented here would only work for genes that are expressed at similar levels / similar ranges.

More

Upvote

VOTE

Downvote
Eric Snyder  Follow
thanks, this works well! The general approach will be useful moving forward with a number of other analyses as well. Thanks!More
Upvote

VOTE

Downvote