Warm tip: This article is reproduced from stackoverflow.com, please click
violin-plot seurat

Change the y limits ( especially the minimum) with Vlnplot

发布于 2020-04-20 11:26:12

I would like to draws a violin plot from my single cell data.

I use this function : Vlnplot(object, features, cols = NULL, pt.size = 0.1)

But I would like to change the y axis from 3000-10000 instead of 0 to 70000.

They only propose to change the y max but not the mean

Does someone have an idea how to do it ?

Questioner
Juliette Leon
Viewed
11
erilu 2020-03-06 13:20

The VlnPlot function in the Seurat R package uses ggplot2 to draw the violin plot. This means we can modify the y-axis using scale_y_continuous.

In your case, to change the y-axis of your violin plot to 3000-10000, we would write:

VlnPlot(object, features, cols = NULL, pt.size = 0.1) + scale_y_continuous(limits = c(3000,10000))

To show you a reproducible example, we can draw a violin plot using the pbmc_small dataset from the Seurat package:

VlnPlot(pbmc_small, "CD3E")

default violin plot

The plot above has a default axis of 0 to around 6.3. Here is how the same plot looks like after altering the y-axis using scale_y_continuous, in which I zoom in between 0 and 3:

VlnPlot(pbmc_small, "CD3E") + scale_y_continuous(limits = c(0,3))

violin plot after changing axis

Many of the other visualizations in the Seurat package also use ggplot2, so you can make all types of cosmetic changes to them using various ggplot2 commands (themes, axis labels, colors, etc.)