| er_style_tte_curve | R Documentation |
Builder functions for the curve layer (er_tte_add_curve()),
drawing the Kaplan-Meier estimate as a step function with an optional
step-shaped confidence band.
er_style_tte_curve_km(
data,
config,
stratify,
time,
strata,
theme,
show_ci = TRUE,
ribbon_alpha = 0.15,
linewidth = 1,
...
)
data |
The original data frame ( |
config |
Configuration for the curve layer (populated by
|
stratify |
Logical: whether the fit is stratified
( |
time |
|
strata |
|
theme |
|
show_ci |
Whether to draw the confidence band. Default |
ribbon_alpha |
Transparency of the confidence band ( |
linewidth |
Width of the step curve's line. Default |
... |
Additional named arguments forwarded from
|
See er_style_tte() for the shared interface every TTE-grammar
builder implements.
A Kaplan-Meier confidence band is a step function, just like the
curve itself, but ggplot2 has no built-in "step ribbon" geom (unlike
ggplot2::geom_step() for the line). er_style_tte_curve_km() works
around this with ggplot2::geom_rect(): one rectangle per interval
between consecutive event/censoring times, with xmin/xmax the
interval's start/end time and ymin/ymax the interval's constant
lower/upper bound – visually identical to a step ribbon, without
needing a bespoke stat.
Stratified colour/fill both map to config$table's own strata
column (the already-cleaned stratum label, e.g. "Q1" or a
categorical level) rather than the original stratify_by column on
data, since that's what config$table actually carries.
er_tte_build() retitles the resulting legend with strata$label
(e.g. "sex") afterwards, so a builder itself never needs to know
the original variable's name.
er_style_tte_curve_km() is tagged er_style_tag(fn, layer = "curve"), so er_tte_add_curve() errors informatively if handed a
builder tagged for a different layer.
A geom, or a list of geoms.
er_tte_add_curve(), er_style_tte()
library(survival)
lung |>
er_tte(time, status == 2) |>
er_tte_add_curve(style = er_style_tte_curve_km, ribbon_alpha = 0.3) |>
plot()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.