Skip to contents

Produces a step function confidence interval for survival curves.

Usage

geom_stepconfint(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  na.rm = FALSE,
  ...
)

Arguments

mapping

Aesthetic mappings with aes() function. Like geom_ribbon(), you must provide columns for x, ymin (lower limit), ymax (upper limit).

data

The data to be displayed in this layer. Can inherit from ggplot parent.

stat

The statistical transformation to use on the data for this layer, as a string. Defaults to 'identity'.

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

...

Optional. Any other ggplot geom_ribbon() arguments.

Note

Adapted from the survminer package <https://github.com/kassambara/survminer>.

Examples

library(survival)
library(ggplot2)

fit <- survfit(Surv(time, status) ~ trt, data = diabetic)
fit <- survfit0(fit) # connect origin

ggplot(
  data = data.frame(
    time = fit$time,
    surv = fit$surv,
    conf.low = fit$lower,
    conf.high = fit$upper,
    strata = rep(names(fit$strata), fit$strata)
  ),
  mapping = aes(x = time, y = surv)
) +
  geom_step(aes(color = strata)) +
  geom_stepconfint(aes(ymin = conf.low, ymax = conf.high, fill = strata), alpha = 0.3) +
  coord_cartesian(c(0, 50)) +
  scale_x_continuous(expand = c(0.02,0)) +
  labs(x = 'Time', y = 'Freedom From Event') +
  scale_color_manual(
    values = c('#d83641', '#1A45A7'),
    name = 'Treatment',
    labels = c('None', 'Laser'),
    aesthetics = c('colour', 'fill')) +
  theme_basic()