Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggsurvplot - Breaking legend in to rows

Tags:

r

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)
like image 808
user8271418 Avatar asked Jul 07 '17 14:07

user8271418


People also ask

How do I change the legend position in Ggsurvplot?

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.

How to make legend two rows in ggplot?

Now to fold the legend, add guides() function with color as guide_legend() together with parameter nrow=2, which folds legend into two-row.


1 Answers

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.

like image 126
user8271418 Avatar answered Nov 15 '22 08:11

user8271418