Skip to contents

This function is used to draw a violin plot of selected features among self-defined groups from a sparse eset object.

Usage

feature_vlnplot(
  input_eset,
  features = NULL,
  group_by = "clusterID",
  ncol = 3,
  colors = NULL,
  legend.position = "right",
  fontsize.legend_title = 10,
  fontsize.legend_text = 8,
  fontsize.strip = 10,
  fontsize.axis_title = 10,
  fontsize.axis_text = 8,
  xlabel.angle = 0,
  ylabel.text = "Expression (log2CPM)",
  stat_method = "median",
  add_boxplot = FALSE,
  boxplot.width = 0.3,
  boxplot.fill = "white",
  boxplot.alpha = 0.8,
  add_jitter = FALSE,
  jitter.height = 0,
  jitter.width = 0.3,
  jitter.size = 0.1
)

Arguments

input_eset

The expression set object that filtered, normalized and log-transformed

features

A vector of genes or drivers (row.names of the input eset) to plot

group_by

Character, name of the column for grouping, usually the column of cell types or clusters. Default: "clusterID".

ncol

Integer, number of columns when multiple plots are displayed. Default: 3.

colors

A vector of colors for filling the violins. The length should be same as the number of groups. Default: NULL (ggplot default colors).

legend.position

Character, position of legend: "right" (the default), "left", "top", "bottom" or "none".

fontsize.legend_title

Integer, font size of the legend title. Default: 10.

fontsize.legend_text

Integer, font size of the legend text. Default: 8.

fontsize.strip

Integer, font size of the plot strip. Default: 10.

fontsize.axis_title

Integer, font size of the axis title. Default: 10.

fontsize.axis_text

Integer, font size of the axis text. Default: 8.

xlabel.angle

Numeric, the angle of the a-axis title. When it's set not 0, the x-axis text will automatically right-justified. Default: 0.

ylabel.text

Character, the title of y-axis. Default: "Expression (log2CPM)"

stat_method

Character or NULL. method of the stat point to show: "median" (the default), "mean". If NULL, the stat point won't show up.

add_boxplot

Logical, whether to add box plot. Default: FALSE.

boxplot.width

Numeric, width of the box plot relative to the body of violin plot, ranging from 0 to 1. Default: 0.3. Ignored if add_boxplot = FALSE.

boxplot.fill

Character, color used to fill the box plots. Default: "white". Ignored if add_boxplot = FALSE.

boxplot.alpha

Numerical, transparency of box plots, ranging from 0 (more transparent) to 1 (less transparent). Default: 0.8. Ignored if add_boxplot = FALSE.

add_jitter

Logical, whether to add jittered points. Default: FALSE.

jitter.height

Numeric, amount of vertical jitter. Default: 0.

jitter.width

Numeric, amount of horizontal jitter. Default: 0.3.

jitter.size

Numeric, size of the jittered points. Default: 0.1.

Value

A ggplot object with one or multiple violin plots

Examples

data(pbmc14k_expression.eset)

## 1. violin plots grouped by clusters (say the column name is 'clusterID')
p_vln <- feature_vlnplot(input_eset = pbmc14k_expression.eset,
                         features = c("CD14", "CD19", "CD8A"),
                         group_by = "clusterID")

## 2. violin plots grouped by cell types (say the column name is 'cellType')
p_vln <- feature_vlnplot(input_eset = pbmc14k_expression.eset,
                         features = c("CD14", "CD19", "CD8A"),
                         group_by = "cellType")

## 3. customize the colors to fill the violin plots
p_vln <- feature_vlnplot(input_eset = pbmc14k_expression.eset,
                         features = c("CD14", "CD19", "CD8A"),
                         group_by = "clusterID",
                         colors = c("blue", "red", "green", "orange", "purple", "grey", "brown"))

## 4. add jittered points
p_vln <- feature_vlnplot(input_eset = pbmc14k_expression.eset,
                         features = c("CD14", "CD19", "CD8A"),
                         group_by = "clusterID",
                         add_jitter = TRUE, jitter.width = 0.5, jitter.size = 0.5)