Skip to contents

Creates a PCA dimensionality reduction plot with variance explained percentages automatically added to axis labels. When split.by is used, shows each split category with a grey silhouette of all other cells.

Usage

do_PcaPlot(
  object,
  dims = c(1, 2),
  group.by = NULL,
  split.by = NULL,
  colors.use = NULL,
  label = TRUE,
  label.size = 4,
  label.color = "black",
  label.fill = "white",
  pt.size = 1,
  pt.alpha = 1,
  plot.axes = TRUE,
  variance_digits = 1,
  shuffle = TRUE,
  plot_cell_borders = TRUE,
  border.size = 2,
  border.color = "black",
  legend.title = NULL,
  show.legend = TRUE,
  ncol = NULL,
  nrow = NULL,
  ...
)

Arguments

object

Seurat object.

dims

numeric. Vector of 2 PC dimensions to plot (default: c(1, 2)).

group.by

character. One or more metadata columns for grouping. If NULL (default), uses active Idents. When multiple columns are provided, each gets its own panel combined via patchwork.

split.by

character. Metadata column for splitting (creates panels with silhouettes).

colors.use

Named vector of colors for groups.

label

logical. Show cluster labels (default: TRUE).

label.size

numeric. Label font size (default: 4).

label.color

character. Label text color (default: "black").

label.fill

character. Label background fill (default: "white").

pt.size

numeric. Point size (default: 1).

pt.alpha

numeric. Point transparency (default: 1).

plot.axes

logical. Show axes (default: TRUE).

variance_digits

numeric. Decimal places for variance (default: 1).

shuffle

logical. Randomize cell plotting order (default: TRUE).

plot_cell_borders

logical. Plot black borders around cells (default: TRUE).

border.size

numeric. Border size multiplier (default: 2).

border.color

character. Border color (default: "black").

legend.title

character. Custom legend title (NULL removes title).

show.legend

logical. Show the colour legend (default: TRUE). Set to FALSE to hide the legend entirely.

ncol

numeric. Number of columns for panel layout (default: NULL, auto). Controls layout of both split panels and multi-column group.by panels.

nrow

numeric. Number of rows for panel layout (default: NULL, auto).

...

Additional arguments (currently unused).

Value

ggplot2 object with PCA plot including variance explained in axis labels.

Examples

if (FALSE) { # \dontrun{
do_PcaPlot(seurat_object, group.by = "condition")
do_PcaPlot(seurat_object, dims = c(2, 3), group.by = "cluster")
do_PcaPlot(seurat_object, split.by = "sample")  # Shows silhouettes
} # }