| er_style_tte_summary | R Documentation |
Builder functions for the summary layer (er_tte_add_summary()),
drawing a corner-placed text/label annotation from a log-rank test
comparing survival across stratify_by's levels, a supplied model's
er_summary() result, or observation/event counts.
er_style_tte_summary_logrank(
data,
config,
stratify,
time,
strata,
theme,
inset = 0.05,
label_size = NULL,
label_colour = NULL,
label_fill = NULL,
...
)
er_style_tte_summary_n(
data,
config,
stratify,
time,
strata,
theme,
inset = 0.05,
label_size = NULL,
label_colour = NULL,
label_fill = NULL,
...
)
er_style_tte_summary_coefficients(
data,
config,
stratify,
time,
strata,
theme,
inset = 0.05,
label_size = NULL,
label_colour = NULL,
label_fill = NULL,
...
)
er_style_tte_summary_gof(
data,
config,
stratify,
time,
strata,
theme,
inset = 0.05,
fields = c("n", "aic", "bic", "r_squared"),
label_size = NULL,
label_colour = NULL,
label_fill = NULL,
...
)
data |
The original data frame ( |
config |
Configuration for the summary layer (populated by
|
stratify |
Logical: whether this layer was added with
|
time |
|
strata |
|
theme |
|
inset |
Distance from the panel edge for the annotation label,
as a fraction of the panel's width/height. Default |
label_size |
Label text size. Defaults to |
label_colour |
Label text colour. Defaults to |
label_fill |
Label background fill. Defaults to |
... |
Additional named arguments forwarded from
|
fields |
Fields from |
See er_style_tte() for the shared builder interface these
functions implement.
A geom, or a list of geoms.
Each builder draws a different kind of annotation, with its own data requirements:
er_style_tte_summary_logrank() (the default) – a log-rank
p-value comparing survival across stratify_by's levels. Draws
nothing on an unstratified object, or one with fewer than 2 strata
levels present in the data.
er_style_tte_summary_n() – subject/event counts. Doesn't depend
on a model or stratify_by at all.
er_style_tte_summary_coefficients() – one line per row of a
supplied model's coefficients table (see er_summary()). Draws
nothing without a model supplying coefficients, or if the layer
is stratified.
er_style_tte_summary_gof() – a single-line goodness-of-fit
summary from a supplied model's glance field. Same requirements
and restrictions as er_style_tte_summary_coefficients().
er_style_tte_summary_logrank() places its annotation in whichever
of the panel's 4 corners is currently furthest from the survival
curve(s), using the same (0, 1)-rescaled corner-distance
calculation er_plot_add_summary()'s own p-value annotation uses to
avoid a plot's raw data points – here applied to the curve's own
(time, surv) coordinates instead, since there's no raw per-subject
scatter in this grammar for the annotation to avoid. It draws nothing
if config$logrank_p_value is NULL (fewer than 2 strata levels
present, including an unstratified object).
er_style_tte_summary_n() draws subject and event counts – one line
per stratum when stratify is TRUE, a single overall line
otherwise – and doesn't depend on a model or stratify_by at all.
er_style_tte_summary_coefficients() draws one line per row of the
supplied model's coefficients table (see er_summary()'s
coefficients field); it draws nothing if coefficients wasn't
supplied, or if the layer is stratified. er_style_tte_summary_gof()
draws a single-line, comma-separated goodness-of-fit annotation from
the model's glance field – a curated subset (N, AIC, BIC,
R-squared) rather than every reserved glance column, showing only
whichever of those four are actually present and non-NA; it draws
nothing if none of them are available, or if the layer is stratified.
All four builders are tagged er_style_tag(fn, layer = "tte_summary") – distinct from er_plot_add_summary()'s own
"summary" tag, since the two grammars' summary builders share no
signature (exposure/response vs. time) – so
er_tte_add_summary() errors informatively if a builder tagged for a
different layer is passed to it instead (including
er_plot_add_summary()'s own builders).
er_tte_add_summary(), er_style_tte()
library(survival)
lung |>
transform(sex = factor(sex, labels = c("Male", "Female"))) |>
er_tte(time, status == 2, stratify_by = sex) |>
er_tte_add_curve() |>
er_tte_add_summary(style = er_style_tte_summary_logrank, label_fill = "white") |>
plot()
# a purely descriptive annotation, with no log-rank test at all
lung |>
er_tte(time, status == 2) |>
er_tte_add_curve() |>
er_tte_add_summary(style = er_style_tte_summary_n) |>
plot()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.