autoplot.survfitr: Plot survival curves with ggplot2

View source: R/autoplot.survfitr.R

autoplot.survfitrR Documentation

Plot survival curves with ggplot2

Description

Draws the estimated survival function of a survfitr object as a step function, one colour per group, with an optional pointwise confidence band. The cumulative distribution (fun = "event") and the cumulative hazard (fun = "cumhaz") transformations are also available.

Usage

## S3 method for class 'survfitr'
autoplot(
  object,
  fun = c("surv", "event", "cumhaz"),
  conf.int = TRUE,
  level = 0.95,
  conf.type = c("log-log", "plain"),
  ...
)

Arguments

object

an object of class survfitr (output of survfitr(), psh_fit(), wc_fit() or mlefrailty_fit()).

fun

transformation of the survival curve: "surv" (default, the survival function), "event" (the cumulative probability of an event, 1 - S) or "cumhaz" (the cumulative hazard, -log S).

conf.int

draw the pointwise confidence band? Default TRUE (ignored for estimators without standard errors).

level

confidence level of the band.

conf.type

transformation used for the band: "log-log" (default) or "plain".

...

ignored; kept for compatibility with the generic.

Details

The confidence band is computed from the standard errors of the fit when the estimator provides them (Peña-Strawderman-Hollander and Wang-Chang). With conf.type = "log-log" (default) the limits are obtained on the \log(-\log S) scale, so they always stay inside [0, 1]; "plain" gives the symmetric limits of the base plot.survfitr() method.

Value

A ggplot object, which can be further styled with the usual ggplot2 syntax.

See Also

plot.survfitr() for the base-graphics version, plotEstimators() to compare the three estimators, theme_survrec()

Examples

data(MMC)
fit <- survfitr(Survr(id, time, event) ~ group,
  data = MMC,
  type = "wang-chang"
)
autoplot(fit)
autoplot(fit, fun = "cumhaz", conf.int = FALSE)

# it is a ggplot, so it can be restyled
autoplot(fit) + ggplot2::labs(title = "Migratory Motor Complex")

survrec documentation built on Sept. 22, 2026, 9:07 a.m.