ggfortify
ggfortify copied to clipboard
Merging legends
Looks possible but can't work well with current ggmultiplot
as legend
must be considered as plot (grob). Needs separated class to dot this, or logic to merge the same legends when output.
p <- autoplot(lm(Petal.Width ~ Petal.Length, data = iris), colour = 'Species', data = iris)
grob <- ggplotGrob(p@plots[[1]])
leg <- grob$grobs[[which(grob$layout$name == "guide-box")]]
plots <- lapply(p@plots, function(x) x + theme(legend.position = 'none'))
plots[[5]] <- leg
layout_matrix = rbind(c(1, 2, 5), c(3, 4, 5))
do.call(grid.arrange, c(plots, list(ncol = 3, layout_matrix = layout_matrix))