I'm trying to plot cumulative incidence curves for a competing risk scenario with ggsurvfit::ggcuminc. I'd like to add a risk table, customized to show n.risk and cum.event in the same line (not different line), as explained in the vignette https://www.danieldsjoberg.com/ggsurvfit/reference/add_risktable.html#ref-examples (see third example).
set.seed(1)
summary(time <- rnorm(200, 50, 10))
summary(event <- factor(sample(0:2, 200, replace = TRUE, prob = c(.4,.5,.1)), levels = 0:2, labels = c("censor", "event", "comp.event")))
table(female <- sample(0:1, 200, replace = TRUE), useNA = "ifany")
data <- tibble(time, event, female)
tidycmprsk::cuminc(Surv(time, event)~female, data=data) %>%
ggcuminc(outcome = "event") + add_risktable(risktable_stats = "{n.risk} ({cum.event})")
However, i always get this error
Error in match.arg(rev(risktable_stats), choices = c("n.risk", "cum.censor", : 'arg' should be one of “n.risk”, “cum.censor”, “cum.event”, “n.censor”, “n.event”
Can anyone help in understanding why this is not working, as shown in the vignette?
Thanks for including a reproducible example. Your code runs fine on my machine. Putting multiple stats on one line is a new-ish feature, so perhaps you just need to install the latest ggsurvfit? I am on v1.0.0 in the example below
library(tidyverse)
library(ggsurvfit)
packageVersion("ggsurvfit")
#> [1] '1.0.0'
set.seed(1)
summary(time <- rnorm(200, 50, 10))
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 27.85 43.86 49.51 50.36 56.13 74.02
summary(event <- factor(sample(0:2, 200, replace = TRUE, prob = c(.4,.5,.1)), levels = 0:2, labels = c("censor", "event", "comp.event")))
#> censor event comp.event
#> 78 97 25
table(female <- sample(0:1, 200, replace = TRUE), useNA = "ifany")
#>
#> 0 1
#> 99 101
data <- tibble(time, event, female)
tidycmprsk::cuminc(Surv(time, event)~female, data=data) %>%
ggcuminc(outcome = "event") +
add_risktable(risktable_stats = "{n.risk} ({cum.event})")
#> Warning: Removed 1 row containing missing values (`geom_step()`).
Created on 2024-02-12 with reprex v2.1.0