ggsurvfit {ggsurvfit} | R Documentation |
Plot Survival Probability
Description
Plot survival probabilities (and other transformations) using the results
from survfit2()
or survival::survfit()
; although, the former is recommend
to have the best experience with the ggsurvfit package.
Usage
ggsurvfit(
x,
type = "survival",
linetype_aes = FALSE,
theme = theme_ggsurvfit_default(),
...
)
Arguments
x |
a 'survfit' object created with | |||||||||||
type |
type of statistic to report.
Available for Kaplan-Meier estimates only.
Default is
| |||||||||||
linetype_aes |
logical indicating whether to add | |||||||||||
theme |
a survfit theme. Default is | |||||||||||
... |
arguments passed to |
Value
a ggplot2 figure
Details
This function creates a ggplot figure from the 'survfit' object. To better understand how to modify the figure, review the simplified code used internally:
survfit2(Surv(time, status) ~ sex, data = df_lung) %>% tidy_survfit() %>% ggplot(aes(x = time, y = estimate, min = conf.low, ymax = conf.low, color = strata, fill = strata)) + geom_step()
See Also
Visit the gallery for examples modifying the default figures
Examples
# Default publication ready plot
survfit2(Surv(time, status) ~ sex, data = df_lung) %>%
ggsurvfit() +
scale_ggsurvfit(x_scales = list(breaks = seq(0, 30, by = 6)))
# Changing statistic type
survfit2(Surv(time, status) ~ sex, data = df_lung) %>%
ggsurvfit(type = "cumhaz")
# Configuring KM line type to vary by strata
survfit2(Surv(time, status) ~ sex, data = df_lung) %>%
ggsurvfit(linetype_aes = TRUE) +
scale_ggsurvfit()
# Customizing the plot to your needs
survfit2(Surv(time, status) ~ 1, data = df_lung) %>%
ggsurvfit() +
add_censor_mark() +
add_confidence_interval() +
add_quantile() +
add_risktable() +
scale_ggsurvfit()