I want to make a cumulative incidences plot showing 3 competing risks being: Event X, mortality without event X and healthy survival. I already got a good plot using the ggsurvfit package with survfit2 and ggcuminc functions but I have 2 remaining issues:
- I would like to change the order of competing risks shown in the plot legend
- the Nr at risk table always shows “NA”
I made an example based on my own data using the “casebase” package with it’s dataset bmtcrr
# Required packages
library(ggsurvfit)
library(casebase)
# Data
bmtcrr
bmtcrr$status <- factor(bmtcrr$Status, levels = c("0", "1", "2"), labels = c("Healthy survival", "Mortality ", "Event X"))
bmtcrr$istate <- rep("Healthy survival",177)
bmtcrr$time <- (bmtcrr$ftime/12)
# fitted the data
fit <- survfit2(Surv(time, status) ~ 1, data = bmtcrr, istate = istate)
summary(fit, times = 1:10)
# script for the plot
ggcuminc(fit, outcome = c("Healthy survival", "Mortality ", "Event X"), size = 1.1) +
add_risktable(risktable_stats = "n.risk", stats_label = list(n.risk = "Nr at Risk")) +
add_confidence_interval() +
scale_ggsurvfit(y_scales = list(breaks = seq(0, 1, by = 0.2)))+
labs(title = "cumulative events plot", x = "time (years)") +
theme_bw() + theme(axis.title.x = element_text(size = 14),
axis.title.y = element_text(size = 14),
plot.title = element_text(size = 18, hjust = 0.5),
axis.text = element_text(size = 13),
legend.text = element_text(size = 10),
legend.position = "top")
plot derived from script above:
The plot I got using the ggcuminc function is exaclty what I wanted but there are 2 remaining issues:
-
How can I change the order of the plot legend showing outcome to a different order such as: “healthy survival” – “Event X” – “Mortality”
-
How can i fix the risk table always showing “NA”
I also tried the tidycmprsk::cuminc function to make the fit, but it does not show you the healthy survival decreasing as I want.
Marie Lamberigts is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.