ggsurvplot 中的轴线粗细

Axes line thickness in ggsurvplot

提问人:geek45 提问时间:11/17/2023 最后编辑:geek45 更新时间:11/17/2023 访问量:44

问:

如何用刻度更改轴线粗细?

数据:

library(survminer)
data <- data.frame(time  =c(1,2,3,4),
                    status=rep(c(1,0),4),
                    n=c(1,2,3,4),
                   grp = c(1,1,0,0))
obj  <- Surv(time = data$time, event=data$status) 
fit <- survfit(obj ~ grp, data = data)

我的剧情:

ggsurvplot(
  fit,
  data = data,
  xlim = c(0, 60),
  break.x.by = 20,
  xlab = "Day",
  ylab = c("Survival probability"),
  risk.table = "abs_pct",
  font.x = c(12, face = "bold"),
  font.y = c(12, face = "bold"),
  font.tickslab = c(12),
  font.legend = c(12),
  risk.table.title = "RISK",
  risk.table.col = "black",
  size = 1,
  tables.theme = theme_cleantable() + 
    theme(
      plot.title = element_text(size = 40),
      axis.line.y = element_line(size = 1.5) # Not working
    )
)

但它确实改变了 risk.table 旁边的厚度

如何做到这一点?

R ggplot2 生存分析

评论


答:

3赞 Gregor Thomas 11/17/2023 #1

ggsurvplot返回一个同时包含 a 和 item 的类似 -object 的对象。我们可以像这样直接修改元素:listplottableplot

p = ggsurvplot(##... your code from above)

## just for illustration
class(p)
# [1] "ggsurvplot" "ggsurv"     "list"      
names(p)
# [1] "plot"           "table"          "data.survplot"  "data.survtable"

## adjust the plot theme
p[["plot"]] = p[["plot"]] + theme(axis.line.y = element_line(linewidth = 3))
p

enter image description here

评论

0赞 geek45 11/17/2023
谢谢。我以为我可以在主代码中实现它。我也试了一下km$plot$theme$line$linewidth <- 1.5km$plot$theme$axis.ticks$linewidth <- 1.5
1赞 Gregor Thomas 11/17/2023
这也有效,但您仍然需要修改主题元素,并为其指定一个对象。axis.line.yelement_linekm$plot$theme$axis.line.y = element_line(linewidth = 3)