How do I break the legend into multiple rows? Currently, legend the legend plots as one row, but I would like to output it rows, there are 5 strata on one plot.
Thanks
survival <- survfit(Surv(Statustime, Status)~Strata, data=df1)
ggsurvplot(survival, legend = "bottom",conf.int = TRUE, pval = TRUE, risk.table = FALSE, xlim = c(0,180), break.time.by = 30)
ggsave("survival_ART.png", width = 5, height = 5)
Default is "top" side position. to remove the legend use legend = "none". Legend position can be also specified using a numeric vector c(x, y). In this case it is possible to position the legend inside the plotting area. x and y are the coordinates of the legend box.
Now to fold the legend, add guides() function with color as guide_legend() together with parameter nrow=2, which folds legend into two-row.
I managed to find the answer myself - submitting here in case someone else finds this question and wonder what the answer was.
ggsurvplot(survival, legend = "bottom", conf.int = TRUE, pval = TRUE, risk.table = FALSE) +
guides(colour = guide_legend(nrow = 5))
where nrow = number of strata.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With