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?
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 :
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 :
Another workaround is to save your figure as a pdf and edit it with a tool like inscape to "center" your third figure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With