'Defining particular sub-groups in survival analysis in R

This is the code in R that produces a Kaplan-Meier plot of Overall Survival for a population broken down by Stage.

library(tidyverse)
library(forcats)
library(broom)
library(survival)
library(Hmisc)
library(gmodels)
library(lazyeval)
library(plotrix)
library(summariser)
library(magrittr)
library(survminer)
library(dplyr)
library(lattice)
library(Formula)
library(lubridate)
library(ggfortify)
library(readxl)

icccdata = read_excel("ICCC_All_20072016.xls")
head(icccdata)
km <- with(icccdata, Surv(Time, Status))

# STAGE specific OVERALL SURVIVAL
survival_object2 <- Surv(icccdata$Time, icccdata$CancerSurvival)
str(survival_object2)
my_survfit_STAGE_OS <- survfit(survival_object2 ~ Stage, data = icccdata)
print(my_survfit_STAGE_OS, print.rmean = TRUE)
dat_my_survfit_STAGE_OS <- fortify(my_survfit_STAGE_OS)
ggsurvplot(my_survfit_STAGE_OS, risk.table = TRUE, xlab = "Time (years)", censor = T)

The Stage data consists of the values 0, I, II, III, IV.

I want to be able to just show the values for Stage I, without having the Stage 0, II, III, or IV displayed. I'd appreciate some help with the code to separate out a single sub-group.

A



Solution 1:[1]

I would recommend building your own ggplot() instead of using ggsurvplot(). This can be done by using surv_summary() from the survminer package. This is also what ggsurvplot() is using behind the scenes.

E.g.:

df <- surv_summary(my_survfit_STAGE_OS)
df %>% filter(Stage == "I") %>% 
       ggplot(aes(x = time, y = surv, col = Stage)) + 
       geom_step()

If you want to plot stage I and II you could use %in% like

df %>% filter(Stage %in% c("I", "II")) %>% ggplot(....)

In ggsurvplot() a dataframe from surv_summary() is passed to ggsurvplot_df() and then created using ggplot() based on user options. Check out the R source code here: https://github.com/kassambara/survminer/blob/master/R/ggsurvplot_df.R

If you want an at risk table this can be created using ggrisktable()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michael