Search code examples
rggplot2plot

R ggsurvplot fixing ratio


Im at preparing the last plots for submission but cant get the last things correct. What i want to do is making the plot square and having the risk table follow it size.

I'm using this code ggsurvplot(survfit(Surv(time,event) ~ "(hidden)"), risk.table = T, legend.labs = c("(hidden)","(hidden)"), pval = T, xlab = "Days", ylab= "Cum Survival", xlim = c(0,1000), break.x.by = c(200), surv.plot.height = 2,ggtheme = theme(aspect.ratio = 1)) for my survival plot. enter image description here

But what a get is a square plot but also a square risk table. Any ideas on how to make the code not apply to the risk table?

Sincerely 


Solution

  • To fix the awkward aspect ratio one can specify tables.theme in the call to ggsurvplot. Example:

    library(survminer)
    library(survival)
    
    ggsurvplot(survfit(Surv(time, status)~ sex, data = lung), risk.table = T,
               legend.labs = c("M" ,"F"),
               pval = T,
               xlab = "Days",
               ylab= "Cum Survival",
               xlim = c(0,1000),
               break.x.by = c(200),
               surv.plot.height = 2,
               ggtheme = theme(aspect.ratio = 1),
               tables.theme =  theme(aspect.ratio = 0.2))
    

    enter image description here