Home > Software design >  How to format multiple ggsurvplots when using arrange_ggsurvplots?
How to format multiple ggsurvplots when using arrange_ggsurvplots?

Time:01-06

I'm trying to create a figure in R which includes multiple kaplan-meier curves and label each plot (e.g. A, B, C). I've been able to make a figure using arrange_ggsurvplots, however, the output is very cramped appearing. How can I format the plots (e.g. change plot dimensions, font size) so that the plots in the output are appropriately sized and readable?

Appreciate your time and help.

segst_g_survfit <- survfit(Surv(time/30.4375, statuslife) ~ segst_g, data = good_data)
ehdz_survfit <- survfit(Surv(time/30.4375, statuslife) ~ Extrahepaticdz, data = good_data)
prioranyldt_survfit <- survfit(Surv(time/30.4375, statuslife) ~ prioranyldt, data = good_data)
hepaticresect <- survfit(Surv(time/30.4375, statuslife) ~ hepaticresection, data = good_data)
tsize_g_survfit <- survfit(Surv(time/30.4375, statuslife) ~ tsize_g, data = good_data)
segstx_g_survfit <- survfit(Surv(time/30.4375, statuslife) ~ segstx_g, data = good_data)

splots <- list()


splots[[1]] <- ggsurvplot(
    fit = hepaticresect, 
    legend = c(0.75,0.8),
    legend.labs=c("No Resection","Prior Resection"),
    title ="OS vs Prior Hepatic Resection",
    pval=TRUE,
    pval.coord = c(4,0),
    xlab = "Months", 
    ylab = "Survival Probability", conf.int=FALSE)   labs(tag='A')
splots[[2]] <-  ggsurvplot(
    fit = prioranyldt_survfit, 
    legend = c(0.75,0.8),
    legend.labs=c("Prior Liver Directed Therapy","No Prior Liver Directed Therapy"),
    title ="OS vs Prior Liver Directed Therapy",
    pval=TRUE,
    pval.coord = c(4,0),
    xlab = "Months", 
    ylab = "Survival probability", conf.int=FALSE)   labs(tag='B')
splots[[3]] <- ggsurvplot(
    fit = segst_g_survfit, 
    legend = c(0.75,0.8),
    legend.labs=c("Greater than 2 segments","Less than or equal to 2 segments"),
    title ="OS vs Number Segments with Tumor",
    pval=TRUE,
    pval.coord = c(4,0),
    xlab = "Months", 
    ylab = "Survival Probability", conf.int=FALSE)   labs(tag='C')
splots[[4]] <- ggsurvplot(
    fit = segstx_g_survfit, 
    legend = c(0.75,0.8),
    legend.labs=c("Greater than 3 segments","Less than or equal to 3 segments"),
    title ="OS vs Hepatic Segments Treated",
    pval=TRUE,
    pval.coord = c(4,0),
    xlab = "Months", 
    ylab = "Survival Probability", conf.int=FALSE)   labs(tag='D')
splots[[5]] <- ggsurvplot(
    fit = tsize_g_survfit, 
    pval=TRUE,
    pval.coord = c(4,0),
    title ="OS vs Largest Tumor Size",
    legend = c(0.75,0.8),
    legend.labs=c("Greater than 4 cm","Less than or equal to 4 cm"),
    xlab = "Months", 
    ylab = "Survival probability", conf.int=FALSE)   labs(tag='E')
splots[[6]] <- ggsurvplot(
    fit = ehdz_survfit, 
    legend = c(0.75,0.8),
    legend.labs=c("No Extrahepatic Disease","Extrahepatic Disease"),
    title ="OS vs Extrahepatic Disease",
    pval=TRUE,
    pval.coord = c(4,0),
    xlab = "Months", 
    ylab = "Survival Probability", conf.int=FALSE)    labs(tag='F')

arrange_ggsurvplots(splots,print=TRUE,ncol=2,nrow=3)

Cramped output:

enter image description here

CodePudding user response:

Try piping the output to ggsave, and change the size to the proportions you like

myplot %>% ggsave(device="png", filename="Figure.png", width = 15, height = 5, units = "in")

I think what you are experiencing is simply the display in rstudio being a little cramped.

  • Related