plotVariableFeature: Plot variance modelling results

View source: R/func_sc.R

plotVariableFeatureR Documentation

Plot variance modelling results

Description

This function requires a SingleCellExperiment object and the resulting DataFrame after performing variance modelling, such as modelGeneVar() from the scran package, and produces a mean-variance scatter plot.

Usage

plotVariableFeature(
  sce,
  var,
  hvg = NULL,
  top_n = 10,
  point_size = 2,
  text_size = 4,
  text_color = "black",
  trend_color = "gold",
  trend_size = 2,
  box.padding = 0.5,
  max.overlaps = Inf,
  seed = 12321,
  xlab = "Mean log-counts",
  ylab = "Variance of log-counts",
  title = NULL,
  theme_size = 18,
  ...
)

Arguments

sce

A SingleCellExperiment object.

var

A DataFrame returned by variance modelling functions such as modelGeneVar(), modelGeneVarByPoisson(), etc.

hvg

A character vector containing a set of highly variable genes to highlight in red. Default is NULL.

top_n

An integer scalar indicating the first top_n genes to label. When hvg = NULL, the first top_n genes with the highest mean are selected. When HVGs are provided, the first top_n HVGs are selected. Default is 10.

point_size

A numeric scalar indicating the size of the points. Default is 2.

text_size

A numeric scalar indicating the size of the label. This is passed to geom_text_repel(). Default is 4.

text_color

A string indicating the colour of the label. This is passed to geom_text_repel(). Default is "black".

trend_color

A string indicating the colour of the smoothed curve. Default is "gold",

trend_size

A numeric scalar indicating the size of the smoothed curve. Default is 2.

box.padding

A scalar indicating the amount of padding around bounding box, as unit or number. This is passed to geom_text_repel(). Default is 0.5.

max.overlaps

Exclude text labels that overlap too many things. This is passed to geom_text_repel(). Default is Inf.

seed

Random seed passed to set.seed(). This is passed to geom_text_repel(). Default is 12321.

xlab

The title of the x-axis. Default is "Mean log-counts".

ylab

The title of the y-axis. Default is "Variance of log-counts".

title

Plot title. Default is NULL.

theme_size

A numeric scalar indicating the base font size. Default is 18.

...

Other arguments passed on to geom_text_repel().

Details

In addition to the two required inputs, if rowData(sce) has is_pass and/or is_ambient columns containing logical values (i.e. TRUE and FALSE), denoting if a gene passed QC or if its expression is attributable to ambient contamination, the resulting figure will show the genes in different shapes. Also, genes that are HVGs are coloured in red when a gene list is provided using the hvg argument.

Value

A ggplot object

Author(s)

I-Hsuan Lin

See Also

scran::modelGeneVar(), scran::modelGeneVarByPoisson(), scran::modelGeneVarWithSpikes(), ggrepel::geom_text_repel()

Examples

library(SingleCellExperiment)

# Load demo dataset
data(sce)

var <- metadata(sce)[["modelGeneVar"]]
hvg <- metadata(sce)[["HVG"]]

# View modelGeneVar result
plotVariableFeature(sce, var, top_n = 5, title = "modelGeneVar")

# Highlight HVGs
plotVariableFeature(sce, var, hvg, title = "modelGeneVar (highlight HVGs)")

ycl6/scRUtils documentation built on Feb. 18, 2025, 6:14 a.m.