Skip to contents

This function highlight a cluster on a dimensional reduction in NPG palette with highlight on top.

Usage

plot_highlight_cluster(
  obj,
  cluster_id,
  reduction = NULL,
  group.by = NULL,
  highlight.col = NULL,
  other.col = "grey80",
  pt.size = 0.6,
  pt.shape = 16,
  raster = NULL,
  dpi = 300,
  legend = TRUE,
  legend_labels = NULL,
  legend_breaks = NULL,
  legend_pos = NULL
)

Arguments

obj

Seurat object.

cluster_id

Value to highlight (in Idents(obj) or obj[[group.by]]).

reduction

Dimred name; default active reduction.

group.by

Metadata column; NULL uses Idents.

highlight.col

Highlight color; NULL -> ggsci NPG red.

other.col

Background color (default "grey80").

pt.size

Point size.

pt.shape

Point shape (ggplot2 pch), default 16.

raster

Logical or NULL; NULL auto-enable when >1e5 cells.

dpi

Single numeric DPI for raster geoms (default 300).

legend

Show legend (default TRUE).

legend_labels

Named vector to rename legend entries; must include c("highlight","other"). Defaults to c(highlight=cluster_id, other="other").

legend_breaks

Character vector to set legend order/visibility; accepts keys in c("highlight","other") or their display labels in legend_labels. Default c("highlight","other"). Use "highlight" only to hide "other".

legend_pos

Legend position (inside); NULL uses ggplot2 default (outside, right).

Value

ggplot object.

Examples

if (FALSE) { # \dontrun{
# load demo data
data("pbmc_small", package = "SeuratObject")

# 1) Basic: highlight first cluster on PCA
plot_highlight_cluster(
  pbmc_small,
  cluster_id = levels(Seurat::Idents(pbmc_small))[1],
  reduction = "pca", pt.size = 0.5, raster = FALSE)

# 2) Use UMAP
pbmc_small <- Seurat::RunUMAP(
  pbmc_small, reduction = "pca", dims = 1:10)
plot_highlight_cluster(
  pbmc_small, cluster_id = "0",
  reduction = "umap", pt.size = 0.6, raster = FALSE)

# 3) Custom colors
plot_highlight_cluster(
  pbmc_small, cluster_id = "0", reduction = "pca",
  highlight.col = "#377EB8", other.col = "grey85")

# 4) Hide legend
plot_highlight_cluster(
  pbmc_small, cluster_id = "0", reduction = "pca",
  legend = FALSE)

# 5) Rename legend entries
plot_highlight_cluster(
  pbmc_small, cluster_id = "0", reduction = "pca",
  legend_labels = c(highlight = "Yes", other = "No"),
  legend_breaks = c("highlight", "other"))

# 6) Show only highlight in legend
plot_highlight_cluster(
  pbmc_small, cluster_id = "0", reduction = "pca",
  legend_labels = c(highlight = "Yes", other = "No"),
  legend_breaks = "highlight")

# 7) Rasterization
plot_highlight_cluster(
  pbmc_small, cluster_id = "0", reduction = "pca",
  raster = TRUE, dpi = 500)

# 8) Metadata column grouping
pbmc_small$Stage1 <- ifelse(
  as.character(Seurat::Idents(pbmc_small)) == "0",
  "Control", "Other")
plot_highlight_cluster(
  pbmc_small, cluster_id = "Control",
  group.by = "Stage1", reduction = "pca")

# 9) Inside legend position
plot_highlight_cluster(
  pbmc_small, cluster_id = "Control",
  group.by = "Stage1", reduction = "pca",
  legend_pos = c(0.8, 0.8))
} # }