Skip to contents

Computes cell-type proportions across ordered levels of a grouping variable (e.g., time points or conditions), displays them as a stacked area + bar chart, and places ggrepel::geom_text_repel() labels at the rightmost position so each cell type is identified without a legend.

Usage

PlotTrendLabeled(
  seurat_object,
  stat.by,
  group.by,
  split.by,
  colors = NULL,
  group.levels = NULL,
  label.side = "right",
  bar.width = 0.6,
  label.size = 3,
  label.nudge = 0.1,
  label.margin = 120,
  segment.size = 0.4,
  max.overlaps = 100,
  hjust = 1,
  show.legend = FALSE,
  border.size = 0.5,
  base_size = 12,
  nrow = NULL,
  ncol = NULL,
  output_dir = NULL,
  file_name = NULL,
  object_name = NULL,
  subset_name = NULL,
  width = NULL,
  height = NULL
)

Arguments

seurat_object

A Seurat object.

stat.by

Character. Metadata column whose proportions are plotted (e.g., cell type assignments). This becomes the fill color.

group.by

Character. Ordered x-axis variable (e.g., "TimePoint").

split.by

Character. Metadata column that defines independent panels.

colors

Named character vector mapping stat.by levels to colors.

group.levels

Character vector. Explicit ordering of group.by levels. NULL uses factor or alphabetical order.

label.side

Character. Where to place labels: "right" (default, last x position) or "both" (first and last).

bar.width

Numeric. Width of stacked bars. Default 0.6.

label.size

Numeric. ggrepel text size. Default 3.5.

label.nudge

Numeric. Horizontal nudge for labels (in x-axis units). Default 0.3.

label.margin

Numeric. Right plot margin (pt) to accommodate labels. Default 80.

segment.size

Numeric. Connector line width. Default 0.4.

max.overlaps

Integer. Passed to ggrepel::geom_text_repel(). Default 100.

hjust

Numeric. Horizontal justification for ggrepel labels (0 = left-aligned, 1 = right-aligned). Default 1.

show.legend

Logical. Show a fill legend? Default FALSE (labels replace the legend).

border.size

Numeric. Panel border line width. Default 0.5.

base_size

Numeric. Base font size. Default 12.

nrow, ncol

Integer or NULL. Number of rows/columns for the panel grid. NULL (default) auto-arranges into a single row.

output_dir

Character or NULL. Directory to save the PDF. Walks up from PrepObject() settings when NULL.

file_name

Character or NULL. Base filename (no extension). Auto- deduced from object_name, subset_name, and column names when NULL, always ending in "TrendLabeled" - a saved file ending in that suffix was made by this function, useful for working backward from a saved PDF without its analysis_params.json.

object_name

Character. Prefix for the auto-deduced filename.

subset_name

Character. Second prefix component.

width, height

Numeric. PDF dimensions in inches. Auto-sized when NULL.

Value

A patchwork object (one panel per split.by level). Returns invisibly when saved to disk.

Details

Panels are faceted by split.by and combined with patchwork::wrap_plots(). One panel per split.by level is produced.