Seurat: No legend in VlnPlot() split.by

Created on 10 Feb 2020  路  2Comments  路  Source: satijalab/seurat

Seurat rookie here. I am using Seurat 3.1.2 and I want to use the argument "split.by" in the VlnPlot() function to visualize QC metrics for samples which are or are not fluorescent.
My code is

VlnPlot(object, 
             features = c("nFeature_RNA", 
                                   "nCount_RNA", 
                                   "percent.mt"), 
                      ncol = 3, 
                      log = TRUE, 
                      pt = 0.1,
                      split.by = "fluorescence",
                      group.by = "construct")

and gives this as output
Screenshot 2020-02-10 at 14 57 53

Questions

  1. How do I get a legend to show me which samples (fluorescent or not) are which color (red or blue) color in the split violin plots?
    I tried the code below, which gives me the graph above without a legend:
plot_runid <- VlnPlot(EF1a_object, 
                      features = c("nFeature_RNA", 
                                   "nCount_RNA", 
                                   "percent.mt"), 
                      ncol = 3, 
                      log = TRUE, 
                      pt = 0.1,
                      split.by = "fluorescence",
                      group.by = "construct") + theme(legend.position = 'right')
  1. How do I plot the median? I tried the code below but the graph looks identical to above.
VlnPlot(object, 
             features = c("nFeature_RNA", 
                                   "nCount_RNA", 
                                   "percent.mt"), 
                      ncol = 3, 
                      log = TRUE, 
                      pt = 0.1,
                      split.by = "fluorescence",
                      group.by = "construct") + stat_summary(fun.y = median, fun.ymin = median, fun.ymax = median, geom = "crossbar", width = 0.5)

Many thanks!

Analysis Question

Most helpful comment

Hi,

Not member of the Dev team but hopefully this can be helpful (and is correct). I believe that both of the issues that you are having are related to the fact that when you provide multiple features to VlnPlot it is actually using CombinePlots() under the hood and theming doesn't work with combine plots in Seurat. You should be able to manually get around the issues by creating individual plots saved to the environment:

p1 <- VlnPlot(object, "nCount_RNA", pt.size = 0.1, split.by = "fluorescence", group.by = "construct")) + stat_summary(fun.y = median, fun.ymin = median, fun.ymax = median, geom = "crossbar", width = 0.5)
p2 <- VlnPlot(object, "nFeature_RNA", pt.size = 0.1, split.by = "fluorescence", group.by = "construct")) + stat_summary(fun.y = median, fun.ymin = median, fun.ymax = median, geom = "crossbar", width = 0.5)

Then combine with cowplot package
plot_grid(p1, p2)

Hope that helps and solves the issue. Also Dev team or others please correct me if I'm wrong.
Best,
Sam

All 2 comments

Hi,

Not member of the Dev team but hopefully this can be helpful (and is correct). I believe that both of the issues that you are having are related to the fact that when you provide multiple features to VlnPlot it is actually using CombinePlots() under the hood and theming doesn't work with combine plots in Seurat. You should be able to manually get around the issues by creating individual plots saved to the environment:

p1 <- VlnPlot(object, "nCount_RNA", pt.size = 0.1, split.by = "fluorescence", group.by = "construct")) + stat_summary(fun.y = median, fun.ymin = median, fun.ymax = median, geom = "crossbar", width = 0.5)
p2 <- VlnPlot(object, "nFeature_RNA", pt.size = 0.1, split.by = "fluorescence", group.by = "construct")) + stat_summary(fun.y = median, fun.ymin = median, fun.ymax = median, geom = "crossbar", width = 0.5)

Then combine with cowplot package
plot_grid(p1, p2)

Hope that helps and solves the issue. Also Dev team or others please correct me if I'm wrong.
Best,
Sam

Hi Sam,

I tested it, and it works! I get the legend and the median.
Many thanks, it was torturing me the whole day!

Best,
Corina

Was this page helpful?
0 / 5 - 0 ratings

Related issues

igordot picture igordot  路  3Comments

kathirij picture kathirij  路  3Comments

GHAStVHenry picture GHAStVHenry  路  3Comments

bio-la picture bio-la  路  3Comments

rajasreemenon picture rajasreemenon  路  3Comments