add_label: Add labels to reduced dimension plots

View source: R/func_sc.R

add_labelR Documentation

Add labels to reduced dimension plots

Description

This function is designed to be used with scater::plotReducedDim() from the scater package without specifying text label (i.e. via text_by). Then use add_label() to place labels centrally.

Usage

add_label(
  sce,
  dimname = "TSNE",
  text_by = "label",
  text_type = "text",
  text_size = 8,
  text_color = "black",
  box.padding = 0.5,
  max.overlaps = 20
)

Arguments

sce

A SingleCellExperiment object.

dimname

A string or integer scalar indicating the reduced dimension result in reducedDims(sce) to plot. Default is "TSNE".

text_by

A string indicating the column metadata field with which to add text labels on the plot. Alternatively, a character vector of the same length as colData(sce) indicating the labels of each cell. Default is "label".

text_type

A string indicating to add text directly to the plot ("text") or draw a rectangle underneath the text ("label"). Default is "text".

text_size

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

text_color

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

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 20.

Details

The repel-away-from-center behaviour in plotReducedDim() should be fixed in scater v1.23.5.

Value

A geom (geometric object)

Author(s)

I-Hsuan Lin

See Also

scater::plotReducedDim()

Examples

library(scater)

# Load demo dataset
data(sce)

plotReducedDim(sce, "TSNE", colour_by = "label") + add_label(sce, "TSNE")

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