I am doing a cumulative incidence analysis on two competing events. What i am trying to do, is expanding on the risk table, making it breakdown both event type AND strata.

MRE using the Melanoma dataset:

library(ggsurvfit)
library(tidycmprsk)
library(dplyr)

data(Melanoma, package = "MASS")

Melanoma \<- Melanoma %\>%mutate(
status = as.factor(recode(status, `2` = 0, `1` = 1, `3` = 2)))

Melanoma$sex\[Melanoma$sex == 1\] \<-"male"
Melanoma$sex\[Melanoma$sex == 0\] \<-"female"

cuminc(Surv(time, status) \~ sex, data = Melanoma) %\>%
ggcuminc(outcome = c("1", "2")) +
labs(
x = "Days") +
add_risktable()

Output plot

I tried using the method outlined here, to build the risk table myself:

How can I add a risk table with the breakdown of each event type in the cumulative incidence function plot using 'ggcuminc'?

Like so:

cuminc <- cuminc(Surv(time, status) ~ sex, data = Melanoma)

gg_risktable <- 
  cuminc |> 
  tidy_cuminc(times = c(0, 5, 10, 15, 20)) |> 
  select(outcome, time, n.risk, cum.event) %>%
  {distinct(., time, n.risk) |> 
      mutate(outcome = "At Risk") |> 
      rename(stat = n.risk) |> 
      bind_rows(select(., outcome, time, stat = cum.event))} |> 
  ggplot(aes(x = time, y = factor(outcome), label = stat)) +
  geom_text(size = 3) +
  labs(y = NULL, x = NULL) +
  theme_light() +
  theme(
    panel.grid.minor = element_blank(),
    panel.grid.major = element_blank()
  )
gg_risktable

However, it seems the strata makes the numbers overlap into a smudge (pictured). (https://i.stack.imgur.com/Mu7kt.png)

Is there any way to solve this, or is it impossible to do with strata?

Any help is appreciated Thanks in advance

Edit: Added example output plot clarity

0

There are 0 best solutions below