Creates a boxplot visualization of the model results from sccomp
. This function plots the estimated cell proportions across samples, highlighting significant changes in cell composition according to a specified factor.
sccomp_boxplot(
.data,
factor,
significance_threshold = 0.05,
test_composition_above_logit_fold_change = attr(.data,
"test_composition_above_logit_fold_change"),
remove_unwanted_effects = FALSE
)
A tibble containing the results from sccomp_estimate
and sccomp_test
, including the columns: cell_group name, sample name, read counts, factor(s), p-values, and significance indicators.
A character string specifying the factor of interest included in the model for stratifying the boxplot.
A numeric value indicating the False Discovery Rate (FDR) threshold for labeling significant cell-groups. Defaults to 0.05.
A positive numeric value representing the effect size threshold used in the hypothesis test. A value of 0.2 corresponds to a change in cell proportion of approximately 10% for a cell type with a baseline proportion of 50% (e.g., from 45% to 55%). This threshold is consistent on the logit-unconstrained scale, even when the baseline proportion is close to 0 or 1.
A logical value indicating whether to remove unwanted variation from the data before plotting. Defaults to FALSE
.
A ggplot
object representing the boxplot of cell proportions across samples, stratified by the specified factor.
# Note: Before running the example, ensure that the 'cmdstanr' package is installed:
# install.packages("cmdstanr", repos = c("https://stan-dev.r-universe.dev/", getOption("repos")))
# \donttest{
if (instantiate::stan_cmdstan_exists()) {
data("counts_obj")
estimate <- sccomp_estimate(
counts_obj,
formula_composition = ~ type,
formula_variability = ~ 1,
.sample = sample,
.cell_group = cell_group,
.count = count,
cores = 1
) |>
sccomp_test()
# Plot the boxplot of estimated cell proportions
sccomp_boxplot(
.data = estimate,
factor = "type",
significance_threshold = 0.05
)
}
# }