Skip to contents

plot_survival() draws the survival curves of a kaplan_meier() fit as step functions, with their pointwise confidence bands and a + at each censoring time. A fit with groups has one curve per group, told apart by color. The result is a ggplot object, so layers, scales, and themes can be added to it.

Usage

plot_survival(
  fit,
  conf_int = TRUE,
  censor_marks = TRUE,
  risk_table = FALSE,
  times = NULL,
  xlab = "Time",
  ylab = "Survival probability"
)

Arguments

fit

A kaplan_meier() fit.

conf_int

Draw the confidence bands.

censor_marks

Mark the censoring times on the curves.

risk_table

Stack a numbers-at-risk table under the curves.

times

The times of the numbers-at-risk table. The default is six evenly spaced, rounded times from 0 to the end of follow-up.

xlab, ylab

The axis labels.

Value

A ggplot object, or a patchwork with risk_table = TRUE.

Details

With risk_table = TRUE, the numbers at risk (see risk_table()) are stacked under the curves, on the same time axis. This needs the patchwork package, and the result is a patchwork.

See also

theme_survival(), risk_table(), and plot_cif() for competing risks.

Examples

fit <- kaplan_meier(Surv(time, status) ~ sex, data = lung)
plot_survival(fit)

plot_survival(fit, conf_int = FALSE, censor_marks = FALSE)


if (requireNamespace("patchwork", quietly = TRUE)) {
  plot_survival(fit, risk_table = TRUE, times = c(0, 250, 500, 750, 1000))
}