plotProjection: Colour cells by a feature in a 2-dimension representation

View source: R/func_sc.R

plotProjectionR Documentation

Colour cells by a feature in a 2-dimension representation

Description

This function uses plotReducedDim() from the scater package to show cells on a pre-calculated low-dimensional projection (such as UMAP or t-SNE) and colour by a choosen cell-specific feature. It uses add_label() to label cells when text_by is used.

Usage

plotProjection(
  sce,
  feature,
  dimname = "TSNE",
  feat_desc = NULL,
  feat_color = NULL,
  color_breaks = waiver(),
  color_limits = NULL,
  exprs_by = "logcounts",
  text_by = NULL,
  point_size = 2,
  point_alpha = 0.5,
  theme_size = 18,
  show_na = FALSE,
  na.value = "grey50",
  legend_pos = "right",
  legend_just = "center",
  guides_ncol = NULL,
  guides_nrow = NULL,
  guides_barwidth = NULL,
  guides_barheight = NULL,
  guides_size = point_size * 2,
  title = NULL,
  show_title = TRUE,
  show_subtitle = TRUE,
  other_fields = list(),
  ...
)

Arguments

sce

A SingleCellExperiment object.

feature

A string indicating the column name in colData(sce) containing the feature to be coloured. Alternatively, a character vector of the same length as colData(sce) indicating the feature type of each cell.

dimname

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

feat_desc

A string that describes the coloured feature. Default is NULL.

feat_color

A character vector of colour codes indicating the colours of the features, or a palette function that creates a vector of colours along a colour map. Default is NULL, and use choosePalette() to select a palette.

color_breaks

For colouring continuous data, one of:

  • NULL for no breaks

  • waiver() for the default breaks (the scale limits)

  • A character vector of breaks

  • A function that takes the limits as input and returns breaks as output

color_limits

For colouring continuous data, one of:

  • NULL to use the default scale range

  • A numeric vector of length two providing limits of the scale. Use NA to refer to the existing minimum or maximum

  • A function that accepts the existing (automatic) limits and returns new limits.

exprs_by

A string or integer scalar specifying which assay from sce to obtain expression values from, for use in point aesthetics. Use assayNames(sce) to find all availavle assays in sce. Default is "logcounts".

text_by

A string indicating the column metadata field with which to add text labels on the plot. Default is NULL.

point_size

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

point_alpha

A numeric scalar (between 0 and 1) indicating the transparency. Default is 0.5.

theme_size

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

show_na

Logical scalar indicating whether to show NA values. Default is FALSE.

na.value

Colour to use for missing values. Default is "grey50".

legend_pos

The position of legends ("none", "left", "right", "bottom","top". Use "none" to disable plot legend. Default is "right".

legend_just

The anchor point for positioning legend inside plot ("center" or two-element numeric vector) or the justification according to the plot area when positioned outside the plot. Default is "center".

guides_ncol, guides_nrow

An integer scalar indicating the desired number of column and row of discrete legends. Default is NULL.

guides_barwidth, guides_barheight

A numeric or a grid::unit() object specifying the width and height of the colourbar. Default is NULL.

guides_size

An integer scalar indicating the desired size of the points in a discrete legend. Default is point_size * 2.

title

Plot title. Default is NULL and the dimname is used as title.

show_title

Logical scalar indicating whether to show plot title. Default is TRUE.

show_subtitle

Logical scalar indicating whether to show plot subtitle, Default is TRUE.

other_fields

Additional cell-based fields to include in the DataFrame. Default is list().

...

Other arguments passed on to add_label().

Details

The function uses plotReducedDim() from the scater package to create a base plot and adds aesthetic, such as point colours, legend controls, title and subtitles, to the final figure.

Value

A ggplot object

Author(s)

I-Hsuan Lin

See Also

scater::plotReducedDim()

Examples

# Load demo dataset
data(sce)

# Colour and label cells by cluster
plotProjection(sce, "label",
  dimname = "TSNE", text_by = "label",
  feat_desc = "Cluster"
)

# Colour cells by DKD62 expression and label by cluster
plotProjection(sce, "DKD62",
  dimname = "UMAP", text_by = "label",
  feat_desc = "DKD62 Expression", guides_barheight = 15
)

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