3

I need to add letters eg A and B to the resulting 2 Kaplan Meier curves plots

code

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

So I need the resulting plot like this

enter image description here

Mohamed Rahouma
  • 1,084
  • 9
  • 20

1 Answers1

4

Calling ggsurvplot(...,risk.table=TRUE,...) creates a list that holds a plot and a table. You can access the plot with splots[[...]]$plot and then add a figure label with 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")

enter image description here

gregor-fausto
  • 435
  • 2
  • 9
  • @gregor.fausto Thx a lot. Greatly appreciated. upvoted. Please let me know if there is a way to control this annotation"A" and "B" font size. – Mohamed Rahouma Aug 23 '21 at 00:29
  • You can control the font size of the tags with `theme(plot.tag=element_text(...))`. See https://stackoverflow.com/questions/28243514/ggplot2-change-title-size for an example of how to use `element_text()`. – gregor-fausto Aug 23 '21 at 16:18