I created this survival plot (dataset=lung) with ggsurvfit which uses ggplot2.
library(survival)
library(ggplot2)
library(ggsurvfit)
p <- survfit2(Surv(time, status)~sex, data=lung)
p %>%
ggsurvfit(type = "survival", linewidth=1) +
labs(
title = "Kaplan-Meier Curve",
y = "Survival probability",
x = "Time, days") +
coord_cartesian(xlim=c(0, 100)) +
add_legend_title("Sex") +
scale_x_continuous(breaks = c(0, 25, 50, 75, 100)) +
scale_y_continuous(expand = c(0.01, 0)) +
scale_color_manual(values = c('violetred2',
'dodgerblue2')) +
scale_fill_manual(values = c('violetred2',
'dodgerblue2')) +
theme_gray() +
theme(legend.position = "bottom") +
add_censor_mark() +
add_confidence_interval() +
add_risktable(risktable_height = 0.25,
theme =
list(
theme_risktable_boxed(axis.text.y.size = 11,
plot.title.size = 11),
theme(plot.title =
element_text(face = "bold"))
)) +
#add_risktable_strata_symbol(symbol = "\U25CF", size = 10)
add_pvalue(caption="Log-rank {p.value}",
location = "annotation", x =10, y=0.15) +
add_quantile(x_value = 15, linetype = "dotted",
color = "grey30", linewidth = 0.8)
I have two problems:
- Why is there some white space on the left part of the plot? It is not symmetrical with the right part (see image, the plot is moved more to the right side and I don't understand why)
- How do I move the risk tables upwards so that there is less space between the plot/legend and the tables? I want to change the "ratio" of the distance between the table and the plot