Skip to contents

Visualizes the composition between two metadata variables (e.g. cluster and sample) as stacked, 100\ complementary panels are produced:

  1. Group → Split: "What percentage of each cluster comes from each sample?"

  2. Split → Group: "How are clusters distributed within each sample?"

Usage

PlotComposition(
  seurat_object,
  group.by,
  split.by,
  plot_type = "percent",
  both_panels = TRUE,
  show_counts = FALSE,
  group_colors = NULL,
  split_colors = NULL,
  output_dir = NULL,
  object_name = "",
  subset_name = "",
  file_name = NULL,
  width = NULL,
  height = NULL,
  timestamp = FALSE
)

Arguments

seurat_object

A Seurat object.

group.by

Primary grouping variable (e.g. cluster, cell type).

split.by

Secondary variable (e.g. sample, condition).

plot_type

One of "percent" (100\ "stacked" (raw cell counts), or "dodged" (side-by-side bars).

both_panels

Logical. If TRUE (default) both group→split and split→group panels are shown side by side. FALSE returns only the group→split panel.

show_counts

Logical. Overlay cell-count labels on bars. Default FALSE.

group_colors

Named character vector of colors for group.by levels. Auto-assigned from PrepObject or Nour_pal if NULL.

split_colors

Named character vector of colors for split.by levels. Auto-assigned from PrepObject or Nour_pal if NULL.

output_dir

Directory to save a PDF. NULL = no save.

object_name

Label prefix for output file names.

subset_name

Optional subset label.

file_name

Character or NULL. Base name (no extension) for the saved PDF. NULL (default) auto-deduces from object_name, subset_name, group.by, and split.by.

width, height

Numeric or NULL. Override the auto-calculated PDF dimensions in inches. NULL (default) auto-sizes to fit the panel(s).

timestamp

Logical. When TRUE, append a _YYYYMMDD-HHMMSS stamp to the saved file name so repeated runs are versioned instead of overwriting the previous PDF. Default FALSE.

Value

A ggplot2 or patchwork object.