Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change a value in a risk table in ggsurvplot

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:

enter image description here

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.

like image 321
J Louro Avatar asked Oct 20 '25 21:10

J Louro


1 Answers

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

res

like image 85
Tim G Avatar answered Oct 23 '25 12:10

Tim G



Donate For Us

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