Skip to contents

Color cells in 3D reduction space, or draw an interactive density surface.

Usage

CellDimPlot3D(
  srt,
  group.by,
  plot_type = c("scatter", "density_surface"),
  reduction = NULL,
  dims = c(1, 2, 3),
  axis_labs = NULL,
  palette = "Chinese",
  palcolor = NULL,
  bg_color = "grey80",
  pt.size = 1.5,
  cells.highlight = NULL,
  cols.highlight = "black",
  shape.highlight = "circle-open",
  sizes.highlight = 2,
  lineages = NULL,
  lineages_palette = "Dark2",
  density_n = 200,
  density_bandwidth = 1,
  density_threshold = 0.018,
  density_power = 0.52,
  density_colors = c("#ffffff", "#edf9fa", "#c7e6ed", "#7faac2", "#294a74", "#11162f",
    "#7f1025", "#ef3b2c"),
  density_color_stops = c(0, 0.02, 0.12, 0.35, 0.62, 0.82, 0.93, 1),
  density_surface_opacity = 0.78,
  density_label = FALSE,
  density_label_color = TRUE,
  density_label_top_n = Inf,
  density_label_min_distance = 0.08,
  density_show_axes = TRUE,
  density_show_colorbar = TRUE,
  density_show_title = TRUE,
  span = 0.75,
  width = NULL,
  height = NULL,
  save = NULL,
  force = FALSE,
  verbose = TRUE
)

Arguments

srt

A Seurat object.

group.by

Metadata column(s) used to color cells.

plot_type

"scatter" (3D points) or "density_surface" (kernel density of the first two dimensions).

reduction

Reduction to plot. NULL uses DefaultReduction.

dims

For "scatter", a length-3 vector of x/y/z dimensions. For "density_surface", the first two dimensions are x/y and density is z.

axis_labs

Length-3 axis labels.

palette, palcolor

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

bg_color

Color for background / NA points.

shape.highlight

Shape of the cell to highlight. See scattergl-marker-symbol

density_n

Grid size used by MASS::kde2d() for plot_type = "density_surface".

density_bandwidth

Bandwidth passed to MASS::kde2d(). A single value scales the default x and y bandwidth; a two-length vector supplies absolute x and y bandwidths.

density_threshold

Relative density values below this cutoff are removed from the surface.

density_power

Power transform applied to relative density before plotting. Values below 1 broaden peaks.

density_colors

Colors used for the density surface. The last colors are reserved for the highest density peaks.

density_color_stops

Numeric stops between 0 and 1 for density_colors. By default, red is reserved for the highest density peaks.

density_surface_opacity

Opacity for density surfaces.

density_label

Whether to add group labels to the density surface.

density_label_color

Whether group labels use the same palette as CellDimPlot().

density_label_top_n

Maximum number of group labels to draw.

density_label_min_distance

Minimum distance between labels in the x-y embedding space, expressed as a fraction of the larger embedding range.

density_show_axes, density_show_colorbar, density_show_title

Whether to show axes, colorbar, and title for plot_type = "density_surface".

span

The span of the loess smoother for lineages line.

width

Width in pixels, defaults to automatic sizing.

height

Height in pixels, defaults to automatic sizing.

save

The name of the file to save the plot to. Must end in ".html".

force

Draw even when a grouping has more than 100 levels.

verbose

Whether to print messages.

Examples

data(pancreas_sub)
pancreas_sub <- RunStandardWorkflow(
  pancreas_sub,
  nonlinear_reduction_dims = 3
)
#>  [2026-08-30 04:05:58] Start standard processing workflow...
#>  [2026-08-30 04:05:58] Checking a list of <Seurat>...
#> ! [2026-08-30 04:05:58] Data 1/1 of the `srt_list` is "unknown"
#> Warning: Data 1/1 of the `srt_list` is "unknown"
#>  [2026-08-30 04:05:58] Perform `NormalizeData()` with `normalization.method = 'LogNormalize'` on 1/1 of `srt_list`...
#>  [2026-08-30 04:05:58] Perform `FindVariableFeatures()` on 1/1 of `srt_list`...
#>  [2026-08-30 04:05:58] Use the separate HVF from `srt_list`
#>  [2026-08-30 04:05:58] Number of available HVF: 2000
#>  [2026-08-30 04:05:58] Finished check
#>  [2026-08-30 04:05:58] Perform `ScaleData()`
#>  [2026-08-30 04:05:58] Perform pca linear dimension reduction
#>  [2026-08-30 04:05:59] Use stored estimated dimensions 1:23 for Standardpca
#>  [2026-08-30 04:05:59] Perform `Seurat::FindClusters()` with `cluster_algorithm = 'louvain'` and `cluster_resolution = 0.6`
#>  [2026-08-30 04:05:59] Reorder clusters...
#>  [2026-08-30 04:05:59] Skip `log1p()` because `layer = data` is not "counts"
#>  [2026-08-30 04:05:59] Perform umap nonlinear dimension reduction
#>  [2026-08-30 04:05:59] Perform umap nonlinear dimension reduction using Standardpca (1:23)
#>  [2026-08-30 04:06:03] Standard processing workflow completed
CellDimPlot3D(
  pancreas_sub,
  group.by = "SubCellType",
  reduction = "StandardpcaUMAP3D"
)
CellDimPlot3D( pancreas_sub, group.by = "SubCellType", plot_type = "density_surface", reduction = "umap", dims = c(1, 2), density_label = TRUE )
pancreas_sub <- RunSlingshot( pancreas_sub, group.by = "SubCellType", reduction = "StandardpcaUMAP3D", show_plot = FALSE ) CellDimPlot3D( pancreas_sub, group.by = "SubCellType", reduction = "StandardpcaUMAP3D", lineages = "Lineage1" )