
Cell Composition Bar Charts
PlotComposition.RdVisualizes the composition between two metadata variables (e.g. cluster and sample) as stacked, 100\ complementary panels are produced:
Group → Split: "What percentage of each cluster comes from each sample?"
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.FALSEreturns 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.bylevels. Auto-assigned from PrepObject orNour_palifNULL.- split_colors
Named character vector of colors for
split.bylevels. Auto-assigned from PrepObject orNour_palifNULL.- 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 fromobject_name,subset_name,group.by, andsplit.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-HHMMSSstamp to the saved file name so repeated runs are versioned instead of overwriting the previous PDF. DefaultFALSE.