ggsurvplot_group_by: Survival Curves of Grouped Data sets

Description Usage Arguments Details Value Examples

View source: R/ggsurvplot_group_by.R

Description

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.

Usage

1
ggsurvplot_group_by(fit, data, group.by, ...)

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:

  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()

Value

Retuns a list of ggsurvplots.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 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)

Example output

Loading required package: ggplot2
Loading required package: ggpubr
Loading required package: magrittr
[1] "rx.Obs::sex"     "rx.Lev::sex"     "rx.Lev+5FU::sex"
[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"

survminer documentation built on March 9, 2021, 5:07 p.m.