我正在使用 ggsurvplot 生成一个带有风险数字表的 kaplan-meir。我希望我的轴扩展,如图所示。然而,这意味着表格与图不相符。我希望表格中的轴也展开,以便它们对齐。如何做到这一点?
library(survival)
library(survminer)
library(ggpp)
df <- lung
# surv time in months
df$time_months <- df$time/(365.25/12)
km_fit<- survfit(Surv(time_months, status) ~ sex, data = df)
time_int <- 2
# SURV FIT
km_plot <- ggsurvplot(km_fit,
data = df,
risk.table = TRUE,
fontsize = 3,
cumevents = FALSE,
# add.all = TRUE,
# cumevents.title = "Cumulative No. of Events",
risk.table.height = 0.18,
cumevents.height = 0.18,
break.x.by = time_int, # Set x-axis breaks to X months intervals (90 days)
x.tick.by = time_int, # Set x-axis tick marks to X months intervals (90 days)
time.inc = time_int, # Set risk table to group by X months intervals (90 days)
risk.table.by = time_int, # Set risk table to group by X months intervals (90 days)
legend.title = "", # Set legend title
tables.y.text = FALSE, # Remove text next to risk table and just have colours
surv.median.line = "hv",
xlim = c(0, max(km_fit$time*1.2)),
xlab = "Time (months)")
# Customise KM aesthetics
km_plot$table <- km_plot$table +
theme(plot.title = element_text(size = 10, color = "black", face = "bold"))
km_plot$cumevents <- km_plot$cumevents +
theme(plot.title = element_text(size = 10, color = "black", face = "bold"))
km_plot$table$theme$axis.text.y$size <- 8
km_plot$cumevents$theme$axis.text.y$size <- 8
km_plot$table$theme$axis.text.x$size <- 8
km_plot$cumevents$theme$axis.text.x$size <- 8
km_plot$table$theme$axis.title.x$size <- 8
km_plot$cumevents$theme$axis.title.x$size <- 8
km_plot$plot <- km_plot$plot +
scale_y_continuous(expand = c(0,0), breaks = seq(0,1,by=0.1), labels = seq(0,100,by=10), minor_breaks = seq(0, 1, 0.1)) +
scale_x_continuous(expand = c(0,0), breaks = seq(0, round(max(km_plot$data.survplot$time*1.2)), time_int), minor_breaks = seq(0, round(max(km_plot$data.survplot$time*1.2)), time_int / time_int)) +
theme(panel.grid.minor.y = element_line(color = "grey80",
linewidth = 0.5,
linetype = 1),
panel.grid.minor.x = element_line(color = "grey80",
linewidth = 0.5,
linetype = 1),
panel.grid.major.y = element_line(color = "grey80",
linewidth = 0.5,
linetype = 1),
panel.grid.major.x = element_line(color = "grey80",
linewidth = 0.5,
linetype = 1)) +
theme(legend.text = element_text(size = 12, color = "black", face = "bold"))
km_plot