rggplot2ggpubrcowplot

Problem with risk table not showing up when combining multiple tidycmprsk::cuminc plots with cowplot or ggarrange


I'm having problems when trying to combine multiple cuminc plots (with tidycmprsk), the risk table doesn't show up in the final combined plot, either using cowplot, or ggarrange.

df <- tibble::tibble(id = c(1:10), 
                     time = c(3, 15, 8, 9, 7, 12, 18, 20, 6, 14), 
                     status = c(0, 1, 1, 1, 1, 0, 1, 0, 0, 1)) %>% 
          mutate(status = as.factor(status))

p <- cuminc(Surv(time, status)~1, data = df) %>% 
  ggcuminc() +
  add_risktable()

inital plot with the risk table below

I tried to combine 2 plots side by side, but the risk tables disappear

ggarrange(p, p, ncol = 2, nrow = 2)

combined plot without the risk tables


Solution

  • One option would be to switch to patchwork which however still requires to build the ggcuminc plot using ggsurvfit::ggsurvfit_build():

    library(ggsurvfit)
    #> Loading required package: ggplot2
    library(survival)
    library(tidycmprsk)
    library(patchwork)
    
    p <- cuminc(Surv(time, status) ~ 1, data = df) |> 
      ggcuminc() +
      add_risktable()
    #> Plotting outcome "1".
    
    list(
      ggsurvfit::ggsurvfit_build(p),
      ggsurvfit::ggsurvfit_build(p)
    ) |> 
      wrap_plots()