Skip to contents

This function shows the cell density presented in a 2D dimensionality reduction coordinates. Density is shown with coloring and contour lines. A scatter plot of the dimensionality reduction is added as well. The density plot can be splitted by categorical variables (e.g. "dataset"), while the scatter plot will always be shown for all cells in subplots as a reference of the global structure.

Usage

plotDensityDimRed(
  object,
  useDimRed = NULL,
  splitBy = NULL,
  combinePlot = TRUE,
  minDensity = 8,
  contour = TRUE,
  contourLineWidth = 0.3,
  contourBins = 5,
  dot = TRUE,
  dotColor = "grey",
  dotSize = 0.6,
  dotAlpha = 0.3,
  dotRaster = NULL,
  title = NULL,
  legendFillTitle = "Density",
  colorPalette = "magma",
  colorDirection = -1,
  ...
)

Arguments

object

A liger object

useDimRed

Name of the variable storing dimensionality reduction result in the cellMeta slot. Default uses default dimension reduction.

splitBy

Character vector of categorical variable names in cellMeta slot. Split all cells by groupings on this/these variable(s) to produce a density plot containing only the cells in each group. Default NULL.

combinePlot

Logical, whether to utilize plot_grid to combine multiple plots into one. Default TRUE returns combined ggplot. FALSE returns a list of ggplot or a single ggplot when only one plot is requested.

minDensity

A positive number to filter out low density region colored on plot. Default 8. Setting zero will show density on the whole panel.

contour

Logical, whether to draw the contour line. Default TRUE.

contourLineWidth

Numeric, the width of the contour line. Default 0.3.

contourBins

Number of contour bins. Higher value generates more contour lines. Default 5.

dot

Logical, whether to add scatter plot of all cells, even when density plot is splitted with splitBy. Default TRUE.

dotColor, dotSize, dotAlpha

Numeric, controls the appearance of all dots. Default "grey", 0.6 and 0.3, respectively.

dotRaster

Logical, whether to rasterize the scatter plot. Default NULL automatically rasterizes the dots when number of total cells to be plotted exceeds 100,000.

title

Text of main title of the plots. Default NULL. Length of character vector input should match with number of plots generated.

legendFillTitle

Text of legend title. Default "Density".

colorPalette

Name of the option for scale_fill_viridis_c. Default "magma".

colorDirection

Color gradient direction for scale_fill_viridis_c. Default -1.

...

More theme setting arguments passed to .ggplotLigerTheme.

Value

A ggplot object when only one plot is generated, A ggplot object combined with plot_grid when multiple plots and combinePlot = TRUE. A list of ggplot when multiple plots and combinePlot = FALSE.

Examples

# Example dataset has small number of cells, thus cutoff adjusted.
plotDensityDimRed(pbmcPlot, minDensity = 1)