I am using the grid lpackage to place my graphs that I made with ggplot2:
library(ggplot2)
library(grid)
Layout <- grid.layout(nrow = 4, ncol = 4,
widths = unit(1, "null"),
heights = unit(c(0.4, 0.8, 1.2, 1.2), c("null", "null", "null")))
grid.show.layout(Layout)
plot1 = ggplot(diamonds, aes(clarity, fill = color)) +
geom_bar() +
facet_wrap(~cut, nrow = 1)
print(plot1 + theme(legend.position = "none"),
vp = viewport(layout.pos.row = 3, layout.pos.col = 1:4))
The problem is that I want to put the plot on the third row (3,1) - (3,4) and put the legend at the (4,4) position. Unfortunately, I can't really find a way to create just a legend variable.
I searched online and the closest that I got was using the older
+ opts(keep = "legend_box")
but that has been deprecated.