plotProjections: Colour cells by a feature in two 2-dimension representation...

View source: R/func_sc.R

plotProjectionsR Documentation

Colour cells by a feature in two 2-dimension representation side-by-side

Description

This function make use of plotProjection() to show cells on two pre-calculated low-dimensional projection (such as UMAP and t-SNE) in a compound figure.

Usage

plotProjections(
  sce,
  feature,
  dimnames = c("TSNE", "UMAP"),
  feat_desc = NULL,
  feat_color = NULL,
  color_breaks = waiver(),
  color_limits = NULL,
  exprs_by = "logcounts",
  text_by = NULL,
  point_size = 1,
  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,
  titles = NULL,
  show_title = TRUE,
  show_subtitle = TRUE,
  other_fields = list(),
  add_void = FALSE,
  rel_widths = c(15, 1),
  rel_heights = c(15, 1),
  ...
)

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.

dimnames

A character or integer vector of length 2 indicating the reduced dimension result in reducedDims(sce) to plot. Default is c("TSNE", "UMAP").

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

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.

titles

A character vector of length 2 indicating the plot title. Default is NULL and the dimnames is used as titles.

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().

add_void

Logical scalar indicating whether to add a completely empty theme using ggplot2::theme_void() in place of the legend. This is applicable when legend_pos = "none". The empty theme is added to the right of the main plot using plot_grid Default is FALSE.

rel_widths

A numeric vector of relative columns widths. For example, in a two-column grid, rel_widths = c(2, 1) would make the first column twice as wide as the second column. This is applicable when legend_pos is "right" or "left". Default is c(15, 1) to make the joined plot 15 times as wide as the legend column if legend_pos = "right".

rel_heights

A numerical vector of relative rows heights. Works just as rel_widths does, but for rows rather than columns. This is applicable when legend_pos is "bottom" or "top". Default is c(15, 1) to make the joined plot 15 times as tall as the legend row if legend_pos = "bottom".

...

Other arguments passed on to add_label().

Details

The function uses plotProjection() to create 2 base plots, then get_Legend() to produce a shared legend and plot_grid() from cowplot to create a compound figure with legend placed at the desired position as specified by legend_pos.

Value

A ggplot2 plot with an object of class c("gg", "ggplot")

Author(s)

I-Hsuan Lin

See Also

plotProjection(), scater::plotReducedDim()

Examples

# Load demo dataset
data(sce)

# Plot TSNE and UMAP side-by-side
plotProjections(sce, "label",
  dimname = c("TSNE", "UMAP"), text_by = "label",
  feat_desc = "Cluster"
)

# Show DKD62 expression
plotProjections(sce, "DKD62",
  dimname = c("TSNE", "UMAP"), text_by = "label",
  feat_desc = "DKD62 Expression", guides_barwidth = 15
)

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