Survival curves of grouped data sets by one or two variables.

Survival analysis are often done on subsets defined by variables in the dataset. For example, assume that we have a cohort of patients with a large number of clinicopathological and molecular covariates, including survival data, TP53 mutation status and the patients' sex (Male or Female).

One might be also interested in comparing the survival curves of Male and Female after grouping (or splitting ) the data by TP53 mutation status.

ggsurvplot_group_by() provides a convenient solution to create a multiple ggsurvplot of a data set grouped by one or two variables.

ggsurvplot_group_by(fit, data,, ...)



a survfit object.


a data frame used to fit survival curves.

a character vector containing the name of grouping variables. Should be of length <= 2.


... other arguments passed to the core function ggsurvplot.


Retuns a list of ggsurvplots.


ggsurvplot_group_by() works as follow:

  1. Create a grouped data sets using the function surv_group_by(), --> list of data sets

  2. Map surv_fit() to each nested data --> Returns a list of survfit objects

  3. Map ggsurvplot() to each survfit object --> list of survfit ggsurvplots

One can (optionally) arrange the list of ggsurvplots using arrange_ggsurvplots()


# Fit survival curves #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: library(survival) fit <- survfit( Surv(time, status) ~ sex, data = colon ) # Visualize: grouped by treatment rx #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ggsurv.list <- ggsurvplot_group_by(fit, colon, = "rx", risk.table = TRUE, pval = TRUE, = TRUE, palette = "jco") names(ggsurv.list)
#> [1] "rx.Obs::sex" "rx.Lev::sex" "rx.Lev+5FU::sex"
# Visualize: grouped by treatment rx and adhere #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ggsurv.list <- ggsurvplot_group_by(fit, colon, = c("rx", "adhere"), risk.table = TRUE, pval = TRUE, = TRUE, palette = "jco") names(ggsurv.list)
#> [1] "rx:Obs, adhere:0::sex" "rx:Obs, adhere:1::sex" #> [3] "rx:Lev, adhere:0::sex" "rx:Lev, adhere:1::sex" #> [5] "rx:Lev+5FU, adhere:0::sex" "rx:Lev+5FU, adhere:1::sex"