Skip to main content

6.5) More On Graphics


Layouts

Whereas par(mfrow=) allows you to create an array of graphs in the order you run them, you you might want to change the positions of graphs without changing the order in which they are run. You can also create more complex layouts where some graphs span multiple rows or columns. All this is possible using layout() with a matrix= argument. The matrix is a sort of map of the graph space you want to create. Its cells should contain numbers that refer to the graph numbers that you want to cover each cell in the matrix: so layout( matrix(c(1,2,3,4,0,5), nrow=2, ncol=3) ) would set up a two-row by three-column grid and put graphs 1–5 into the same positions as if you had used par(mfcol=c(2,3)), except with a blank space at the top right (to avoid confusion, draw a diagram!). Try layout(matrix(c(1,1,4,2,2,4,3,3,4), 3,3)) and then plot a linear model object (output from lm()). Note that the matrix is filled downwards, column by column. (This is different from par(mfrow=), which works horizontally along rows.)