Creates a grouped bar chart comparing performance metrics across cohorts. When a method column is present, bars are dodged by method for comparing multiple approaches (e.g., MOO vs LASSO).

plot_cohort_comparison(
  cohort_metrics,
  metrics = NULL,
  facet_by = c("metric", "cohort"),
  show_values = TRUE,
  value_size = 3,
  y_limits = c(0, 1),
  title = "Per-Cohort Performance Comparison",
  subtitle = NULL
)

Arguments

cohort_metrics

A data.frame from evaluate_panel_by_cohort(), or any data frame with a cohort column and one or more metric columns.

metrics

Character vector specifying which metrics to plot. Defaults to all numeric columns except count columns.

facet_by

One of "metric" (facet by metric, x-axis = cohort) or "cohort" (facet by cohort, x-axis = metric). Defaults to "metric".

show_values

Logical; if TRUE, display metric values as text labels on bars. Defaults to TRUE.

value_size

Numeric; text size for value labels. Defaults to 3.

y_limits

Numeric vector of length 2 specifying y-axis limits, or NULL for automatic limits. Defaults to c(0, 1).

title

Plot title. Defaults to "Per-Cohort Performance Comparison".

subtitle

Optional plot subtitle.

Value

A ggplot object.

Examples

# cohort_metrics <- evaluate_panel_by_cohort(panel, x_list, y_list)
# plot_cohort_comparison(cohort_metrics)
#
# Compare methods:
# moo_metrics$method <- "MOO"
# lasso_metrics$method <- "LASSO"
# plot_cohort_comparison(rbind(moo_metrics, lasso_metrics))