1

How can I have the numbers in the risk table separated with a comma when they are grater then 1,000?

library(survival)
library(survminer)
df <- data.frame(patient = seq(1,10000,1),
                 status = sample(0:1, 10000, replace = T),
                 sex = sample(0:1, 10000, replace = T),
                 time = runif(10000,0,5))

fit <- survfit(Surv(time, status) ~ sex, data = df)
ggsurv <- ggsurvplot(fit, risk.table = TRUE, censor = F,
                     tables.theme = clean_theme())
ggsurv

enter image description here

Edi Itelman
  • 423
  • 5
  • 14

1 Answers1

3

I don't think there's an option to add this within ggsurvplot, so you would need to hack the ggsurv object to change it:

ggsurv$table$layers[[1]]$data$llabels <- 
  scales::comma(ggsurv$table$layers[[1]]$data$llabels)

ggsurv

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • Amazing, thanks! did add ggsurv$table$layers[[1]]$data$llabels <- scales::comma(ggsurv$table$layers[[1]]$data$llabels, accuracy = 1) or because without it it added .0 to all numbers. – Edi Itelman Jul 27 '20 at 16:21