Skip to contents

The VlnPlot function enables visualizing expression levels of feature(s), across clusters using violin plots.

Usage

VlnPlot.SingleCellExperiment(
  object,
  clustering.label,
  features,
  return.plot,
  rotate.x.axis.labels
)

# S4 method for class 'SingleCellExperiment'
VlnPlot(
  object,
  clustering.label,
  features,
  return.plot = FALSE,
  rotate.x.axis.labels = FALSE
)

Arguments

object

of SingleCellExperiment class

clustering.label

A variable name (of class character) available in the cell metadata colData(object) with the clustering labels (character or factor) to use.

features

Feature names to plot by cluster (character) matching row.names(object).

return.plot

return.plot whether to return the ggplot2 object. Default is FALSE.

rotate.x.axis.labels

a logical denoting whether the x-axis labels should be rotated 90 degrees or just draw it. Default is FALSE.

Value

A ggplot2 object if return.plot=TRUE.

Examples

# Import package
suppressPackageStartupMessages(library("SingleCellExperiment"))

# Create toy SCE data
batches <- c("b1", "b2")
set.seed(239)
batch <- sample(x = batches, size = nrow(iris), replace = TRUE)
sce <- SingleCellExperiment(assays = list(logcounts = t(iris[,1:4])),  
                          colData = DataFrame("Species" = iris$Species, 
                                             "Batch" = batch))
colnames(sce) <- paste0("samp", 1:ncol(sce))

# Plot features by clustering/grouping variable
VlnPlot(sce, clustering.label = "Species", 
      features = row.names(sce)[1:4], 
     rotate.x.axis.labels = TRUE)