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.
Arguments
- fit
a survfit object.
- data
a data frame used to fit survival curves.
- group.by
a character vector containing the name of grouping variables. Should be of length <= 2.
- ...
... other arguments passed to the core function
ggsurvplot
.
Details
ggsurvplot_group_by
() works as follow:
Create a grouped data sets using the function
surv_group_by()
, –> list of data setsMap
surv_fit()
to each nested data –> Returns a list of survfit objectsMap
ggsurvplot()
to each survfit object –> list of survfit ggsurvplots
One can (optionally) arrange the list of ggsurvplots using arrange_ggsurvplots()
Examples
# 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, group.by = "rx", risk.table = TRUE,
pval = TRUE, conf.int = 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, group.by = c("rx", "adhere"),
risk.table = TRUE,
pval = TRUE, conf.int = 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"