common legend for multiple plots in r

Solutions on MaxInterview for common legend for multiple plots in r by the best coders in the world

showing results for - "common legend for multiple plots in r"
Sofie
06 Jan 2019
1  plot_colors <- c("blue","black", "green", "orange", "pink")
2  text <- c("Fabricated Metal", "Iron and Steel", "Paper", 
3  "Beverages", "Tobacco")
4  plot.new()
5  par(xpd=TRUE)
6  legend("center",legend = text, text.width = max(sapply(text, strwidth)),
7         col=plot_colors, lwd=5, cex=1, horiz = TRUE)
8  par(xpd=FALSE)
Cameron
02 Jul 2019
1# for ggplot
2ggarrange(bxp, dp,  common.legend = TRUE)