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

I want to annotate (add letters eg A and B) to the resulting 2 Kaplan Meier curves plots using splots and survminer in R

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

代码

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")

所以我需要这样的结果图

调用 ggsurvplot(...,risk.table=TRUE,...) 创建一个包含绘图和 table 的列表。您可以使用 splots[[...]]$plot 访问绘图,然后使用 labs(tag="A").

添加图形标签
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")