You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除添加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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 03:48:18