For legal reasons, in a scientific article, I can´t have numbers lower than 5 in my risk tables, I have to indicate "<5". I tried to access and change the risk table manually but its not working.
library(survival)
library(survminer)
fit <- survfit(Surv(time, status) ~ sex, data = lung)
p <- ggsurvplot(fit, data = lung, risk.table = TRUE)
print(p)
This gives me the following plot:

Now I need that the values "3", "2" and "0", are changed to "<5".
I tried:
library(survival)
library(survminer)
fit <- survfit(Surv(time, status) ~ sex, data = lung)
p <- ggsurvplot(fit, data = lung, risk.table = TRUE)
risk_data <- p$table$data
p$table$data$llabels<-ifelse(p$table$data$llabels<5,"<5",p$table$data$llabels)
which change this values in the object "p$table$data" but when I plot, the result does not change.
It works if you change it within the layers
pacman::p_load(survival, survminer)
fit <- survfit(Surv(time, status) ~ sex, data = lung)
p <- ggsurvplot(fit, data = lung, risk.table = TRUE)
lab <- p$table$layers[[1]]$data$llabels
p$table$layers[[1]]$data$llabels <- ifelse(lab < 5, "<5", lab)
p

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With