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

如何为ComparisonSurv包的Survival.plot生存曲线添加标题?

问题描述

我使用ComparisonSurv包中的Survival.plot函数绘制了对比生存曲线,希望为该图添加标题,请问是否可以通过该函数实现此需求?以下是我的代码:

library(ComparisonSurv)

Survival.plot(
  dat$Primary.to.outcomes..Years., 
  dat$Censor, 
  dat$Cemented.Stem., 
  xlab = "Time (Years)", 
  ylab = "Survival", 
  col = c(1, 4), 
  lwd = c(3, 3), 
  lty= c(1, 1)
)
legend(
  2.5, 
  1, 
  c("no", "yes"), 
  col = c(1, 4), 
  lwd = c(3, 3), 
  lty= c(1, 1), 
  bty="n"
)
解决方案

ComparisonSurv包的Survival.plot函数本身没有内置参数直接设置图标题,不过可以通过以下简单方式添加标题:

方法:用基础绘图的title()函数补加标题

在调用Survival.plot绘制完成后,直接调用R基础绘图系统的title()函数即可添加自定义标题,示例修改后的代码如下:

library(ComparisonSurv)

Survival.plot(
  dat$Primary.to.outcomes..Years., 
  dat$Censor, 
  dat$Cemented.Stem., 
  xlab = "Time (Years)", 
  ylab = "Survival", 
  col = c(1, 4), 
  lwd = c(3, 3), 
  lty= c(1, 1)
)
# 添加标题,可按需调整字体大小、颜色等参数
title(main = "不同骨水泥柄的生存曲线对比", col.main = "black", cex.main = 1.2)
legend(
  2.5, 
  1, 
  c("no", "yes"), 
  col = c(1, 4), 
  lwd = c(3, 3), 
  lty= c(1, 1), 
  bty="n"
)

内容的提问来源于stack exchange,提问作者Sarah

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 08:12:06