We will here use the ggcompetingrisks1 function in the Data & Function page.
# Libraries
library(cmprsk)
library(survminer)
library(ggplot2)# Data used
set.seed(2)
df <- data.frame(del=rexp(100)*5, event=sample(0:2,100,replace=TRUE), groupe=sample(c("A", "B"),100,replace=TRUE))
df$event_surv <- ifelse(df$event==0, 0, 1)# Surv object
fit_gp <- cuminc(df$del, df$event, df$groupe)
fit_surv_gp <- survfit(Surv(del, event_surv)~groupe, data=df)# We set the break time and var_time
break.time.by <- 6
var_time <- "del"
# Display curves
plot.icc.gp=ggcompetingrisks1(
fit_gp, # survfit object with calculated statistics.
xlab = "Time (months)", ylab="Cumulative incidence",
xlim=c(0, 24), ylim=c(0, 1),
title="", legend="top", legend.title="",
conf.int = F,
lwd=1,
event_suppr = 2,
multiple_panels = FALSE,
ggtheme = theme_classic(), # customize plot and risk table with a theme.
) + scale_x_continuous(breaks = seq(0, floor(max(df[, var_time])), break.time.by))
num.icc.gp <- ggrisktable(
fit_surv_gp, # survfit object with calculated statistics.
data=df,
break.time.by = 6, # break X axis in time intervals by 200.
y.text = T, # show bars instead of names in text annotations
fontsize=3,
color = "groupe",
legend="none",
tables.theme = theme_cleantable())
ggarrange(plot.icc.gp, num.icc.gp, ncol = 1, nrow = 2, heights = c(0.85, 0.25), align = "v")
This document is a work by Emma Lafaurie (emma.lafaurie@inserm.fr) for the SBIM (Service de Biostatistique et Information Médicale) at Saint-Louis Hospital in Paris.
Based on the template of Yan Holtz.