Basic Competing Risks Curves With 2 Groups



# 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 by for having the same in ggcompetingrisks1 function and ggrisktable function
break.time.by <- 6

# Display curves with 2 goups
plot.icc.gp=ggcompetingrisks(
  fit_gp,                     # survfit object with calculated statistics.
  break.time.by = break.time.by,                              # break X axis in time intervals by 200.
  xlab = "Time (months)", ylab="Cumulative incidence",
  xlim=c(0, 24), ylim=c(0, 1), 
  title="", legend="top",
  conf.int = F,
  lwd=1,
  multiple_panels = FALSE,
  ggtheme = theme_classic(),                      # customize plot and risk table with a theme.
) + scale_x_continuous(breaks = seq(0, 24, 6)) 
num.icc.gp <- ggrisktable(
  fit_surv_gp,           # survfit object with calculated statistics.
  data=df,
  break.time.by = break.time.by,     # break X axis in time intervals by 200.
  y.text = T,            # show bars instead of names in text annotations
  fontsize=3,
  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")




Contact

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.