Learn R Programming

scUtils (version 0.1.0)

feat: Feature Plot

Description

Highlight gene expression data in a 2D-embedding (UMAP, tSNE, etc.).

Usage

feat(embedding, expression, legend_name = "Expression")

Arguments

embedding

A matrix/data.frame/tibble/... with exactly two columns. If colnames are missing, the axis will be named "Dim1" and "Dim2". Other classes than matrix/data.frame/tibble are possible, as long as data.frame(embedding)) produces a numeric data.frame.

expression

Numeric vector with expression values of the gene of interest. Order has to correspond to the row order in embedding. Typically, expression is normalized gene expression and we recommend k/s/mean(1/s), where k are UMI counts for the gene of interest and s are totalUMI of the cell (aka library size).

legend_name

Text displayed above the legend. Most commonly the name of the displayed gene.

Value

A ggplot2 object storing a colored scatter plot.

Details

This function discourages customization on purpose, because it bundles geoms, themes and settings that I found important for visualizing gene expression in scRNAseq data:

  • coord_fixed, to avoid distortion of embeddings

  • geom_point with size=.4, to ameliorate overplotting

  • No background grid, because distances and axis units in embeddings do not carry meaning for most dimensionality reduction techniques.

  • Intensity-coded color scales (viridis) displayed with log2-transformation. Makes visualization independent of colorblindness and appropriate for gene expression data (which is usually Log Normal distributed).

  • Color scale breaks are displayed as 'closed interval', i.e. max(expression) and min(expression) are the most extreme breaks. Rounding makes them human-readable. This functionality is provided by closed_breaks_log2 and closed_labels.

If you insist on customizing, think of this function as a great starting point, you can simply copy-paste the code after typing feat into your console.

See Also

ggplot, closed_labels, closed_breaks_log2

Examples

Run this code
# NOT RUN {
 # expression goes from 0 to 22:
 set.seed(100)
 feat(matrix(rnorm(2000, c(.1, 3)), ncol=2), rpois(1000, c(.1, 11)))
 # expression goes from 2 to 52:
 set.seed(100)
 feat(matrix(rnorm(2000, c(.1, 3)), ncol=2), rpois(1000, c(10, 31)))
# }

Run the code above in your browser using DataLab