Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arrange plots in a layout which cannot be achieved by 'par(mfrow ='

Tags:

r

graphics

I have three plots which I would to arrange in a single window. I can arrange similar-sized plots on a regular 2*2 grid using par(mfrow = c(2, 2)):

par(mfrow = c(2, 2))
plot(1:10, main = "plot1")
plot(10:1, main = "plot2")
plot(rnorm(10), main = "plot3")

However, I want to position "plot1" and "plot2" beside each other on the top row, and "plot3" below them, centered horizontally. How can I achieve this?

like image 272
Marco Avatar asked Mar 09 '11 09:03

Marco


1 Answers

Not exactly what you are asking for, as the third figure is not horizontally centered but stretched to the full device width, but the layout function allows for a much more flexible configuration.

For example, the following layout definition :

R> layout(matrix(c(1,2,3,3), 2, 2, byrow = TRUE))
R> plot(rnorm(100),col=1)
R> plot(rnorm(100),col=2)
R> plot(rnorm(100),col=3)

Gives the following result :

layout with horizontal third figure

You can also use a "vertical" stretch with the following layout :

R> layout(matrix(c(1,3,2,3), 2, 2, byrow = TRUE))
R> plot(rnorm(100),col=1)
R> plot(rnorm(100),col=2)
R> plot(rnorm(100),col=3)

Which gives :

layout with a vetrtical third figure

Another workaround is to save your figure as a pdf and edit it with a tool like inscape to "center" your third figure.

like image 83
juba Avatar answered Sep 19 '22 15:09

juba