Skip to contents

This function is a stacked violin plot optimized to display features expression in a Seurat object in a grid fashion (square) instead of a single column like other stacked violin functions available in other packages, resulting in nicer plots and easier to include in publications.

Usage

Grid_VlnPlot(
  seurat_object,
  assay = "RNA",
  layer = "data",
  features,
  idents = NULL,
  scale = TRUE,
  rotate.axis = FALSE,
  colors = NULL,
  order.idents = NULL,
  order.colors = TRUE,
  idents.text.size = 9,
  show.idents = FALSE,
  features.text.size = 9,
  legend.text.size = 7,
  legend.side = "bottom",
  show.legend = TRUE,
  ncol = "square"
)

Arguments

seurat_object

A Seurat object.

assay

Character. If the Seurat object contains multiple RNA assays, you may specify which one to use (for example 'RNA2' if you have created a second RNA assay you named 'RNA2'. See Seurat v5 vignettes for more information). You may also use another assay such as 'SCT' to pull features expression from.

layer

Character. Formerly known as slot. It is recommended to use 'data'.

features

Character. A vector of features to plot.

idents

Character. A vector with one or several identities names in the active.ident identity to use if you only want those (instead of subsetting your object). If NULL, all identities will be used.

scale

Logical. If TRUE, scales the violins to have the same max height between features.

rotate.axis

Logical. If TRUE, flips the axis, displaying violins vertically instead of horizontally.

colors

Character. A vector of colors to use for the active.ident identity, of same length as the number of identities in the active.ident identity or supplied to the idents parameter. If NULL, uses Seurat's default colors.

order.idents

Character or Numeric. A vector specifying either 'reverse' or the levels (as character or as numeric values corresponding to the indexes) of the active.ident identity to order the cells.

order.colors

Logical. If TRUE, the colors for the active.ident identity will automatically be ordered according to order.idents. Ignored if order.idents = NULL.

idents.text.size

Numeric. The font size of the identities names. Ignored if show.idents = FALSE.

show.idents

Logical. If TRUE, shows the identities names on the plot.

features.text.size

Numeric. The font size of the features names.

legend.text.size

Numeric. The font size of the legend text. Ignored if show.legend = FALSE.

legend.side

Character. The side where the legend will be displayed, either 'left', 'right', 'top' or 'bottom'. Ignored if show.legend = FALSE.

show.legend

Logical. If TRUE, shows the legend.

ncol

Numeric. Number of columns to use. If 'square', will display features in a square grid or as close as possible depending on number of features.

Value

A ggplot object.

Examples

# Prepare data
pbmc3k <- Right_Data("pbmc3k")
pbmc3k.markers <- c("CCR7", "CD14", "CD40LG",
                    "CD79A", "CD8A", "CDKN1C",
                    "GNLY", "CLEC10A", "PPBP")

# Example 1: default parameters
Grid_VlnPlot(pbmc3k,
             features = pbmc3k.markers)