pharmaverse / ggsurvfit

http://www.danieldsjoberg.com/ggsurvfit/
Other
67 stars 19 forks source link

Feature request: combination of number at risk and cumulative events in Kaplan-Meier risk table #135

Closed RiccardoLeni closed 1 year ago

RiccardoLeni commented 1 year ago

Is it possible to implement the combination of nrisk and cumevent in the add_risktable function of ggsurvfit? To date, it is possible only to have separate features on risktable_stats and these are “n.risk”, “cum.censor”, “cum.event”, “n.censor”, “n.event”.

The result may be a code enclosing the possibility to have something like "n.risk_cum.event" or any other coupling of existing features, resulting in a risk table output of this type (values at random):

Number at risk (cumulative events) 100 (0) 90 (8) 70 (20) ...

Number at risk (cumulative censor) 100 (0) 90 (2) 70 (10) ...

And so on.

Is this feasible? Thanks R

ddsjoberg commented 1 year ago

Perhaps the API could look something like this, where we use glue syntax to place the statistics.

Example of a standard risktable with two rows, one for no. at risk, and a second with the cum. num. events.

survfit2(Surv(time, status) ~ sex, data = df_lung) %>%
  ggsurvfit() + 
  add_risktable(
    risktable_stats = c("n.risk", "cum.event")
  )

To place the stats on both likes, it could look like this: the top row would have the number at risk with the number censored in parenthesis, and the second row would be the cumulative number of events.

survfit2(Surv(time, status) ~ sex, data = df_lung) %>%
  ggsurvfit() + 
  add_risktable(
    risktable_stats = c("{n.risk} ({n.censor})", "{cum.event}")
  )
RiccardoLeni commented 1 year ago

Hi, indeed this would be a perfect solution. I do assume that the line title will automatically report the arguments used before the comma (i.e., "{n.risk} ({n.censor})"), or can it be further personalized (like "Number at risk (Number censored)" or "At risk (censored)" and so on)? Thanks very much for your support.