首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我想使用splots和survminer在R中注释(添加字母,例如A和B)到生成的2个Kaplan Meier曲线图

我想使用splots和survminer在R中注释(添加字母,例如A和B)到生成的2个Kaplan Meier曲线图
EN

Stack Overflow用户
提问于 2021-08-22 15:26:53
回答 1查看 153关注 0票数 2

我需要在生成的2个Kaplan Meier曲线图中添加字母,例如A和B

代码

代码语言:javascript
复制
library(survminer)
# Fit survival curves
require("survival")
fit<- survfit(Surv(time, status) ~ sex, data = lung)
# List of ggsurvplots
require("survminer")
splots <- list()
splots[[1]] <- ggsurvplot(fit, data = lung, risk.table = TRUE, ggtheme = theme_minimal())
splots[[2]] <- ggsurvplot(fit, data = lung, risk.table = TRUE, ggtheme = theme_grey())

# Arrange multiple ggsurvplots and print the output
arrange_ggsurvplots(splots, print = TRUE,
  ncol = 2, nrow = 1, risk.table.height = 0.4)

# Arrange and save into pdf file
res <- arrange_ggsurvplots(splots, print = FALSE)
ggsave("myfile.pdf", res, width = 15, height = 15, units = "cm")

所以我需要像这样的结果图

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-22 17:32:26

调用ggsurvplot(...,risk.table=TRUE,...)会创建一个包含绘图和表格的列表。可以使用splots[[...]]$plot访问打印,然后使用labs(tag="A")添加地物标签。

代码语言:javascript
复制
library(survminer)
# Fit survival curves
require("survival")
fit<- survfit(Surv(time, status) ~ sex, data = lung)
# List of ggsurvplots
splots <- list()
splots[[1]] <- ggsurvplot(fit, data = lung, risk.table = TRUE, ggtheme = theme_minimal()  ) 
splots[[2]] <- ggsurvplot(fit, data = lung, risk.table = TRUE, ggtheme = theme_grey()) 

# access the plot objects and add a tag with labs()
splots[[1]]$plot<-splots[[1]]$plot + labs(tag="A")
splots[[2]]$plot<-splots[[2]]$plot + labs(tag="B")

# Arrange multiple ggsurvplots and print the output
arrange_ggsurvplots(splots, print = TRUE,
                    ncol = 2, nrow = 1, risk.table.height = 0.4)

# Arrange and save into pdf file
res <- arrange_ggsurvplots(splots, print = FALSE)
ggsave("myfile.pdf", res, width = 15, height = 15, units = "cm")

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68882726

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档