我想在ggsurvplot中指定结束时间,如下所示注解生存曲线的端点,但这会导致number-at-risk表中最右边的文本被截断,请参见下面的代码和输出图形,注意在图形中,最右边的值是20和21,但您看到的只是2和2。
如果我增加右侧x轴限值(将xlim=c(-50, time_cutoff)
替换为xlim=c(-50, time_cutoff+50)
),则风险表文本不会被剪切,但生存曲线也会绘制到time_cutoff +50,并且我在生存曲线右侧显示的标签不会与生存曲线的端点对齐。
library(survival)
library(survminer)
library(patchwork)
fit<- survfit(Surv(time, status) ~ sex, data = lung)
# Customized survival curves
my_plot = ggsurvplot(fit, data = lung,
# Add p-value and tervals
risk.table = TRUE,
tables.height = 0.2,
ggtheme = theme_bw() # Change ggplot2 theme
)
time_cutoff = 500
xticks = c(0, 250, 500)
survs = summary(fit, times=time_cutoff)$surv
labels = paste(round(survs*100), '%', sep='')
my_plot$plot <- my_plot$plot +
coord_cartesian(ylim=c(0,1), xlim = c(-50,time_cutoff), clip = 'on', expand=FALSE) +
#scale_x_continuous(name=NULL, breaks = xticks) +
scale_y_continuous(name=NULL, sec.axis=sec_axis(~., name=NULL, breaks = survs, labels= labels))
table_ylim = ggplot_build(my_plot$table)$layout$panel_params[[1]]$y.range
my_plot$table <- my_plot$table +
coord_cartesian(ylim=table_ylim, xlim = c(-50,time_cutoff), clip = 'on', expand=FALSE)# +
#scale_x_continuous(name=NULL, breaks = xticks)
(my_plot$plot / my_plot$table) + plot_layout(heights = c(3,1))
另请参见带长标签的this问题
1条答案
按热度按时间pdsfdshx1#
正如我在回答上一个问题时的注解中提到的,您可以关闭剪切并从表格图中删除面板边框: