Facilitate the creation of stacked probability plots for multi-state survival models with 'ggplot2'. Each function from the package creates a proper 'ggplot2' object that can be modified with any function from the 'ggplot2' or any of its extensions.
The ggstackedsurv package makes the generation of stacked survival
probability plots with ggplot2
easier. It draws heavily from the syntax and the style of
ggsurvfit.
Stacked probability plots are an efficient way to visualize the probabilities of being in each state of a multi-state model over time. Since all patients have to be in one of the states, the probabilities of being in each state at a given time always sum to 1, making for a nice and compact visualization.
A good example can be found in this 2020 paper about extra-corporeal membrane oxygenation (ECMO) in COVID-19 patients (Schmidt et al. 2020)
Originally, the plan was to add these functions as a functionality to
the ggsurvfit package.
However, stacked probability plots are uncommon and out of the scope of
ggsurvfit, so making it a
separate package seemed the right choice.
Plotting stacked probabilities is already possible with the
plot.trans()
function from the mstate package. However, two crucial (imho)
functionalities were lacking:
ggplot2,
which allows for limitless and easy customization, and easy exporting,survival package,
since it is the one mostly used for survival models (even mutlistate
ones).You can install ggstackedsurv from CRAN with:
install.packages("ggstackedsurv")
You can install the development version of ggstackedsurv from
GitHub with:
# install.packages("pak")
pak::pak("ABohynDOE/ggstackedsurv")
The package is quite simple and only produces one type of figure, as shown in the code below
library(ggstackedsurv)
library(survival)
# Create a multi-state model using the ecmo example data
fit <- survfit(Surv(time, status) ~ 1, data = ecmo)
# Plot the survival probabilities of each state over time
ggstackedsurv(fit, base_state = "on ECMO") +
add_risktable()
Schmidt, Matthieu, David Hajage, Guillaume Lebreton, et al. 2020. “Extracorporeal Membrane Oxygenation for Severe Acute Respiratory Distress Syndrome Associated with COVID-19: A Retrospective Cohort Study.” The Lancet Respiratory Medicine 8 (11): 1121–31. https://doi.org/10.1016/S2213-2600(20)30328-3.