Skip to contents

Feature density by group.

Usage

CellDensityPlot(
  srt,
  features,
  group.by = NULL,
  split.by = NULL,
  assay = NULL,
  layer = "data",
  flip = FALSE,
  reverse = FALSE,
  x_order = c("value", "rank"),
  decreasing = NULL,
  palette = "Chinese",
  palcolor = NULL,
  cells = NULL,
  keep_empty = FALSE,
  y.nbreaks = 4,
  y.min = NULL,
  y.max = NULL,
  same.y.lims = FALSE,
  aspect.ratio = NULL,
  title = NULL,
  subtitle = NULL,
  legend.position = "right",
  legend.direction = "vertical",
  theme_use = "theme_scop",
  theme_args = list(),
  combine = TRUE,
  nrow = NULL,
  ncol = NULL,
  byrow = TRUE,
  force = FALSE,
  verbose = TRUE
)

Arguments

srt

A Seurat object.

features

Features to plot.

group.by

Metadata column(s) used to color cells.

split.by

Metadata column to facet by.

assay

Assay to use. NULL uses the default assay.

layer

Assay layer to use.

flip, reverse

Flip the x-axis or reverse the y-axis.

x_order

"value" or "rank".

decreasing

Order groups decreasingly.

palette, palcolor

Palette name (thisplot::show_palettes) or custom colors.

cells

Cell names to include. NULL uses all cells.

keep_empty

Keep empty groups.

y.nbreaks, y.min, y.max

Y-axis breaks and limits. NULL limits are automatic.

same.y.lims

Share y-axis limits across panels.

aspect.ratio

Panel aspect ratio.

title

Plot title. NULL hides the title for merged/single panels. When multiple lineages are plotted and title is NULL, each panel is titled with its lineage column.

subtitle

Plot subtitle.

legend.position

Legend placement ("none", "left", "right", "bottom", "top"), direction, and title. legend.title = NULL uses the group name.

legend.direction

Legend direction: "horizontal" or "vertical".

theme_use, theme_args

Theme name or function, plus extra theme arguments.

combine, nrow, ncol, byrow

Combine plots with patchwork. combine = FALSE returns a list of ggplots.

force

Draw even when there are more than 50 features.

verbose

Whether to print messages.

See also

Examples

data(pancreas_sub)
pancreas_sub <- RunStandardWorkflow(pancreas_sub)
#>  [2026-08-30 04:04:48] Start standard processing workflow...
#>  [2026-08-30 04:04:48] Checking a list of <Seurat>...
#> ! [2026-08-30 04:04:48] Data 1/1 of the `srt_list` is "unknown"
#> Warning: Data 1/1 of the `srt_list` is "unknown"
#>  [2026-08-30 04:04:48] Perform `NormalizeData()` with `normalization.method = 'LogNormalize'` on 1/1 of `srt_list`...
#>  [2026-08-30 04:04:48] Perform `FindVariableFeatures()` on 1/1 of `srt_list`...
#>  [2026-08-30 04:04:49] Use the separate HVF from `srt_list`
#>  [2026-08-30 04:04:49] Number of available HVF: 2000
#>  [2026-08-30 04:04:49] Finished check
#>  [2026-08-30 04:04:49] Perform `ScaleData()`
#>  [2026-08-30 04:04:49] Perform pca linear dimension reduction
#>  [2026-08-30 04:04:49] Use stored estimated dimensions 1:23 for Standardpca
#>  [2026-08-30 04:04:50] Perform `Seurat::FindClusters()` with `cluster_algorithm = 'louvain'` and `cluster_resolution = 0.6`
#>  [2026-08-30 04:04:50] Reorder clusters...
#>  [2026-08-30 04:04:50] Skip `log1p()` because `layer = data` is not "counts"
#>  [2026-08-30 04:04:50] Perform umap nonlinear dimension reduction
#>  [2026-08-30 04:04:55] Standard processing workflow completed
CellDensityPlot(
  pancreas_sub,
  features = "Sox9",
  group.by = "SubCellType"
)
#> Picking joint bandwidth of 0.209


pancreas_sub <- RunSlingshot(
  pancreas_sub,
  group.by = "SubCellType",
  reduction = "UMAP"
)
#> Warning: Removed 7 rows containing missing values or values outside the scale range
#> (`geom_path()`).
#> Warning: Removed 7 rows containing missing values or values outside the scale range
#> (`geom_path()`).


CellDensityPlot(
  pancreas_sub,
  features = "Lineage1",
  group.by = "SubCellType",
  aspect.ratio = 1
)
#> Picking joint bandwidth of 0.459


CellDensityPlot(
  pancreas_sub,
  features = "Lineage1",
  group.by = "SubCellType",
  flip = TRUE
)
#> Picking joint bandwidth of 0.459