I have the following risk table for a Kaplan Meier curve constructed with surv_miner in RStudio:
I would like to string wrap the text in the risk table so that the number is on top, and the percentage (in parenthesis) is on another line below the number, so that they all fit in the table. I tried using the stringr package, but I don't quite know how to incorporate that into the theme. Any help would be appreciated. I've posted just my code, since it is a bit tricky to add the actual survival data. However, if the actual data is needed, I will post some dummy data. Thank you in advance.
require("survival")
require("ggplot2")
require("survminer")
fit <- survfit(Surv(Time, Survival) ~ Gender_bin, data = d)
ggsurvplot(fit,
data = d,
pval = TRUE,
legend.title = "Gender", legend.labs = c("Male", "Female"),
xlab="Time (years)", ylab="Survival",
ggtheme =
theme_bw() +
theme(plot.title = element_text(hjust = 0.5, face = "bold")) +
theme(axis.text=element_text(size=14), axis.title=element_text(size=16), axis.title.x=element_blank()) +
theme(legend.background = element_rect(fill="gray95", size=.5),
legend.text=element_text(size=14), legend.title=element_text(size=14)) +
theme(aspect.ratio=1),
xlim = c(0,10),
break.time.by = 2.5,
legend = c(0.9,0.8),
risk.table = "abs_pct",
fontsize = 3.5,
tables.theme = theme_bw() + theme(aspect.ratio = 0.14) +
theme(axis.text=element_text(size=14), axis.title=element_text(size=14)) +
theme(axis.title.y=element_blank()) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
surv_median(fit)$median