PlotConvergenceProportion: Plot Convergence Proportion

View source: R/composite_score_function.R

PlotConvergenceProportionR Documentation

Plot Convergence Proportion

Description

Draws a 100%-stacked barplot of cell proportions across categories of x_var, colored by a convergence-direction column (fill_var). The color mapping is extracted automatically from meta.data based on the color column generated by CalculateConvergedScore().

Usage

PlotConvergenceProportion(
  seurat_obj,
  x_var,
  fill_var,
  color_var = NULL,
  title = NULL
)

Arguments

seurat_obj

Seurat object whose meta.data holds both fill_var and its matching color column.

x_var

Character. Name of the meta.data column used on the x-axis (e.g. a patient identifier).

fill_var

Character. Name of the meta.data column used to fill the bars.

color_var

Character or NULL. Name of the meta.data column holding the hex color. Defaults to paste0(fill_var, "_Color").

title

Character or NULL. Plot title. Defaults to x_var.

Value

A ggplot object.

Examples

seu_path <- system.file("extdata", "pbmc3k_subset.rds", package = "ConvergeR")
seu <- readRDS(seu_path)
set.seed(42)
seu$SS <- paste0("Patient_", sample(1:5, ncol(seu), replace = TRUE))

# Simulate fast scores to ensure example runs efficiently
seu$Score_IFN <- rnorm(ncol(seu))
seu$Score_Inflam <- rnorm(ncol(seu))

seu <- CalculateConvergedScore(
  seurat_obj = seu,
  principal_score = "Score_IFN",
  other_scores = "Score_Inflam",
  output_colname = "Converged_Immune"
)

p <- PlotConvergenceProportion(
  seurat_obj = seu,
  x_var = "SS",
  fill_var = "Converged_Immune_Direction",
  title = "Immune Convergence by Patient"
)
print(p)

ConvergeR documentation built on Oct. 10, 2026, 5:07 p.m.