Kaplan-Meier plot using ggplot2 and survival.
Usage
create_km_plot(
data,
time_var = "AVAL",
event_var = "CNSR",
trt_var = "TRT01P",
title = "Kaplan-Meier Plot",
xlab = "Time",
ylab = "Survival Probability",
risk_table = FALSE,
show_median = FALSE,
show_ci = FALSE,
show_censor = TRUE,
landmarks = NULL,
xlim = NULL,
palette = NULL,
conf_level = 0.95,
base_size = 11,
type = c("km", "loglog")
)Arguments
- data
ADaMData object or data frame containing survival data
- time_var
Time variable name (default: "AVAL")
- event_var
Event variable name. If "CNSR" (ADaM censoring flag), it will be automatically inverted (0=event becomes 1=event). Otherwise expects 1=event, 0=censor. Default: "CNSR"
- trt_var
Treatment variable name (default: "TRT01P")
- title
Plot title
- xlab
X-axis label
- ylab
Y-axis label
- risk_table
Logical, include risk table below. Requires patchwork.
- show_median
Logical, add horizontal/vertical lines at median survival time (default: FALSE)
- show_ci
Logical, show confidence bands around survival curves (default: FALSE)
- show_censor
Logical, show censoring marks as crosses (default: TRUE)
- landmarks
Numeric vector of timepoints to highlight with vertical lines (e.g., c(12, 24) for 12 and 24 months). NULL for none.
- xlim
Optional x-axis limits as c(min, max)
- palette
Optional color palette for treatment groups. Can be a character vector of colors, or NULL to use
getOption("pharmhand.palette"). Defaults to the CVD-friendly "Okabe-Ito (reordered)" palette (orange, sky blue for first two arms). Other built-in options: "Okabe-Ito", "R4", "Tableau 10", "Alphabet", etc. (seegrDevices::palette.pals()).- conf_level
Confidence level for CI bands (default: 0.95)
- base_size
Base font size for plot text elements (default: 11). Also used for risk table text.
- type
Character. Plot type: "km" for Kaplan-Meier or "loglog" for log(-log(S(t))) vs log(t). For "loglog", median lines, CI bands, risk tables, and landmarks are intentionally omitted to keep the diagnostic scale uncluttered; censor marks are supported via
show_censor.
