如何移除添加risk table后的ggsurvfit绘图白色边框
移除ggsurvfit含风险表时的白色边框
当使用ggsurvfit绘制带风险表(risk table)的生存曲线时,白色边框来自生存曲线绘图面板和风险表面板两个区域,只需在主题设置中针对性移除边框元素即可解决。
修改后的代码
library(ggsurvfit) library(survival) survfit2(Surv(time, status) ~ surg, data = df_colon) |> ggsurvfit() + add_risktable(theme = list( theme_risktable_default(), theme( panel.background = element_rect(fill = "beige"), plot.background = element_rect(fill = "beige", color = NA), panel.border = element_blank(), plot.border = element_blank() ) )) + theme( panel.background = element_rect(fill = "beige"), plot.background = element_rect(fill = "beige", color = NA), legend.background = element_rect(fill = "transparent"), panel.border = element_blank(), plot.border = element_blank() )
关键修改说明
panel.border = element_blank():直接移除面板的白色边框线plot.background的color = NA:将绘图区的外边框设为透明,避免和背景色冲突- 同时在主绘图主题和风险表主题中应用上述设置,确保两个区域的边框都被移除
内容的提问来源于stack exchange,提问作者psoldath
相关产品推荐
相关产品推荐

