I hope I'm not duplicating a question (however I searched and couldn't find), I can't figure out how to draw a common legend with layout_matrix and grid.arrange.
Sample code below:
dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
(p1 = dsamp %>%
ggplot(aes(x=cut, y=carat, color = cut)) +
geom_point())
(p2 = dsamp %>%
ggplot(aes(x=cut, y=depth, color = cut)) +
geom_point())
(p3 = dsamp %>%
ggplot(aes(x=cut, y=table, color = cut)) +
geom_point())
(p4 = dsamp %>%
ggplot(aes(x=cut, y=price, color = cut)) +
geom_point())
(layout_matrix <- matrix(c(1, 1, 1, 1, 2, 2, 3, 4), nrow = 2, byrow = TRUE))
(f = grid.arrange(p1, p2, p3, p4, layout_matrix = layout_matrix))
I would like to plot a common legend for all these plots at the bottom of the layout that I've created