View source: R/ggsurvplot_group_by.R
ggsurvplot_group_by | R Documentation |
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, group.by, ...)
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_group_by
() works as follow:
Create a grouped data sets using the function surv_group_by()
, –> list of data sets
Map surv_fit()
to each nested data –> Returns a list of survfit objects
Map ggsurvplot()
to each survfit object –> list of survfit ggsurvplots
One can (optionally) arrange the list of ggsurvplots using arrange_ggsurvplots()
Retuns a list of 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, group.by = "rx", risk.table = TRUE,
pval = TRUE, conf.int = TRUE, palette = "jco")
names(ggsurv.list)
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.