Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
557 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...