pa_plot_summary: Arrange multiple prediction plots with letter tags

View source: R/plot.R

pa_plot_summaryR Documentation

Arrange multiple prediction plots with letter tags

Description

Builds one panel per data frame using plot_fun (default: pa_plot_pred) and arranges them with letter tags. The function collects a single shared legend and applies global styling (titles, axis labels, legend options) across panels.

Usage

pa_plot_summary(
  data_list,
  titles = NULL,
  plot_fun = pa_plot_pred,
  ncol = 2,
  tag_levels = "a",
  invert_linear = TRUE,
  xlab = "Risk Score",
  ylab = "Days",
  label_name = c("Censored", "Event"),
  levels = NULL,
  shape_style = NULL,
  sample_size = NULL,
  restrict_time = NULL,
  legend_name = "Status",
  seed = NULL
)

Arguments

data_list

List of data frames, each containing columns: linear.pred, pred, times, and status.

titles

Optional character vector, same length as data_list; if NULL, defaults to "Panel 1", "Panel 2", etc.

plot_fun

Function that creates a single panel (default = pa_plot_pred).

ncol

Number of columns in the panel layout (default = 2).

tag_levels

Letter style for tags: "a", "A", "1", "i", or "I".

invert_linear

Logical or logical vector; if length 1, recycled to all panels.

xlab, ylab

Axis labels applied to all panels (defaults are "Risk Score" and "Days").

label_name

Character vector of labels for status legend (e.g., c("censored", "event")).

levels

Numeric vector for status level ordering.

shape_style

Numeric vector of plotting symbols for censoring/event status.

sample_size

Optional integer. If supplied, that many subjects are sampled at random for each panel using seed; otherwise every subject is plotted.

restrict_time

Optional numeric. If supplied, observed times above this value are capped at it and a dashed horizontal reference line is drawn, which keeps a few long follow-up times from compressing the plot.

legend_name

Character string for the legend title (default = "status").

seed

Optional integer. If supplied, the random number generator is seeded with it before sample_size subjects are drawn, so the sampled points are reproducible. The default NULL uses the current random number stream without resetting it; random draws advance its state.

Value

A patchwork ggplot object combining all panels.

Examples

# One panel per model. The previous example referenced undefined objects and
# so could not be executed; this one runs.
d <- pa_sim_cox_weibull(n = 150, pi_c = 0.3, v = 2,
                        beta = c(0.5, -0.5), seed = 2025)
d <- d[, c("time", "status", "x1", "x2")]
cox <- survival::coxph(survival::Surv(time, status) ~ x1 + x2,
                       data = d, x = TRUE, y = TRUE)
wei <- survival::survreg(survival::Surv(time, status) ~ x1 + x2,
                         data = d, dist = "weibull", x = TRUE, y = TRUE)
p_cox <- pa_predict_coxph(model = cox, covs = c("x1", "x2"), new_data = d)
p_wei <- pa_predict_survreg(model = wei, covs = c("x1", "x2"), new_data = d)

pa_plot_summary(
  list(p_cox, p_wei),
  titles = c("Cox PH", "Weibull AFT"),
  ncol = 2,
  legend_name = "Status"
)

PAmeasures documentation built on Oct. 29, 2026, 1:08 a.m.