To add to Henriks's solution, a rather convenient way to use the par () function is:
jpeg(filename="somefile.jpg") op <- par(mfrow=c(2,2)
Thus, you return the parameters back to the old state after running the code. Remember that this is NOT true if one of the sites gave an error.
Remember that R always places the graphs in the same order. Using mfrow fills the grid in a row row by row. If you use mfcol instead of mfrow in your code, you populate the column column by column.
The layout is a completely different story. Here you can determine in which order the plots should be placed. So layout(matrix(1:4,nrow=2) does the same thing as par(mfcol=c(2,2)) . But layout(matrix(c(1,4,3,2),ncol=2)) places the first left chart, the next right one, the third one to the right, and the last left tray.
Each plot is completely independent, so the headers that you specify with the main option are printed. If you want more flexibility, you should take a look at the grid graphics.
Joris meys
source share