Search code examples
rviolin-plotseurat

Change the y limits ( especially the minimum) with Vlnplot


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

I am using this function :

Vlnplot(object, features, cols = NULL, pt.size = 0.1)

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

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

Does someone have an idea how to do it ?


Solution

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