Creates comprehensive visualizations of subgroup results from ForestSearch,
including Kaplan-Meier survival curves, hazard ratio comparisons, and
summary statistics. This function is designed to work with the output
from forestsearch, specifically the df.est component.
plot_sg_results(
fs.est,
outcome.name = "Y",
event.name = "Event",
treat.name = "Treat",
plot_type = c("combined", "km", "forest", "summary"),
by.risk = NULL,
conf.level = 0.95,
est.scale = c("hr", "1/hr"),
sg0_name = "Questionable (H)",
sg1_name = "Recommend (H^c)",
treat_labels = c(`0` = "Control", `1` = "Treatment"),
colors = NULL,
title = NULL,
show_events = TRUE,
show_ci = TRUE,
show_logrank = TRUE,
show_hr = TRUE,
verbose = FALSE,
...
)An object of class fs_sg_plot containing:
List of ggplot2 or base R plot objects
Data frame of subgroup summary statistics
Data frame of hazard ratio estimates
The matched call
A forestsearch object or list containing at minimum:
Data frame with analysis data including treat.recommend
Character vector of subgroup-defining variable names
Optional. Consistency results from sg_consistency_out
Character. Name of time-to-event outcome column. Default: "Y"
Character. Name of event indicator column (1=event, 0=censored). Default: "Event"
Character. Name of treatment column (1=treatment, 0=control). Default: "Treat"
Character. Type of plot to create. One of:
Kaplan-Meier survival curves
Forest plot of hazard ratios
Summary statistics panel
All plots combined (default)
Numeric. Risk interval for KM survival curves. Default: NULL (auto-calculated)
Numeric. Confidence level for intervals. Default: 0.95
Character. Effect scale: "hr" (hazard ratio) or "1/hr" (inverse). Default: "hr"
Character. Label for subgroup 0 (harm/questionable). Default: "Questionable (H)"
Character. Label for subgroup 1 (recommend/complement). Default: "Recommend (H^c)"
Named character vector. Labels for treatment arms. Default: c("0" = "Control", "1" = "Treatment")
Named character vector. Colors for plot elements. Default: uses package defaults
Character. Main plot title. Default: auto-generated
Logical. Show event counts on KM curves. Default: TRUE
Logical. Show confidence intervals. Default: TRUE
Logical. Show log-rank p-value. Default: TRUE
Logical. Show hazard ratio annotation. Default: TRUE
Logical. Print diagnostic messages. Default: FALSE
Additional arguments passed to plotting functions.
When plot_type = "km", creates side-by-side survival curves for:
The identified subgroup (H) with treatment vs control
The complement subgroup (H^c) with treatment vs control
When plot_type = "forest", creates a forest plot showing hazard
ratios with confidence intervals for: ITT population, H subgroup,
and H^c complement.
The function extracts subgroup membership from fs.est$df.est$treat.recommend:
treat.recommend == 0: Harm/questionable subgroup (H)
treat.recommend == 1: Recommend/complement subgroup (H^c)
For est.scale = "1/hr", treatment labels and subgroup interpretation
are reversed to maintain clinical interpretability.
forestsearch for running the subgroup analysis
sg_consistency_out for consistency evaluation
plot_subgroup_results_forestplot for publication-ready forest plots