/survminer

Survival Analysis and Visualization

Primary LanguageR

Build Status CRAN_Status_Badge Downloads Total Downloads Project Status: Active - The project has reached a stable, usable state and is being actively developed. Pending Pull-Requests Github Issues

survminer: Survival Analysis and Visualization

The survminer R package provides functions for facilitating survival analysis and visualization. The current version contains three main functions including:

  • ggsurvplot(): Draws survival curves with the 'number at risk' table.

  • ggcoxzph(): Graphical test of proportional hazards.

  • ggcoxfunctional(): Displays graphs of continuous explanatory variable against martingale residuals of null cox proportional hazards model. It helps to properly choose the functional form of continuous variable in cox model.

Find out more at http://www.sthda.com/english/rpkgs/survminer/, and check out the documentation and usage examples of each of the functions in survminer package.

Installation and loading

Install from CRAN as follow:

install.packages("survminer")

Or, install the latest version from GitHub:

# Install
if(!require(devtools)) install.packages("devtools")
devtools::install_github("kassambara/survminer", build_vignettes = TRUE)

Load survminer:

library("survminer")
# Loading required package: ggplot2

ggsurvplot: Drawing survival curves

  1. Fitting survival curves
require("survival")
# Loading required package: survival
fit <- survfit(Surv(time, status) ~ sex, data = lung)
  1. Basic plots
ggsurvplot(fit)

  1. Customized survival curves
ggsurvplot(fit,  size = 1,  # change line size
           palette = c("#E7B800", "#2E9FDF"), # custom color palettes
           conf.int = TRUE, # Add confidence interval
           pval = TRUE, # Add p-value
           risk.table = TRUE, # Add risk table
           risk.table.col = "strata", # Risk table color by groups
           legend.labs = c("Male", "Female"), # Change legend labels
           risk.table.height = 0.25, # Useful to change when you have multiple groups
           ggtheme = theme_bw() # Change ggplot2 theme
           )

Note that, additional arguments are available to customize the main title, axis labels, the font style, axis limits, legends and the number at risk table.

Blog posts