I need to arrange 4 different plots together in a specific way and I'm trying to use the layout()
function, but just keep getting the wrong results.
If the code was working the way I wanted, the layout would look like this:
so the increase plot is at the top center, decrease plot is bottom center, base21 is left and base22 is right and centered vertically between the others.
Here is the code I have at this point:
layout_matrix <- matrix(c(1, 1, 1, 2, 2, 3, 3, 4, 4, 4), ncol = 3)
# arrange plots using gridExtra and layout
grid.arrange(
arrangeGrob(increase_map, decrease_map, nrow = 3),
arrangeGrob(base21_map, base22_map, ncol = 3),
layout_matrix = layout_matrix
)
How can I get it to arrange like the drawing?
I find it is helpful to write out the layout visually as though you are looking at it, with byrow=TRUE
. E.g.
layout_matrix <- matrix(
c(0,0,0,1,1,1,1,1,0,0,0,
2,2,2,2,2,0,3,3,3,3,3,
0,0,0,4,4,4,4,4,0,0,0),
nrow=3, byrow=TRUE)
Example image of how this looks using layout
/layout.show
in base graphics: