在布局中排列图,这是 'par(mfrow =' 无法实现的 [英] Arrange plots in a layout which cannot be achieved by 'par(mfrow ='

查看:32
本文介绍了在布局中排列图,这是 'par(mfrow =' 无法实现的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个图可以安排在一个窗口中.我可以使用 par(mfrow = c(2, 2)) 在常规 2*2 网格上排列类似大小的图:

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")

但是,我想将plot1"和plot2"并排放置在顶行,将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?

推荐答案

您可能想要layout,您可以通过创建矩阵来设置非常复杂的网格.

You probably want layout, you can set up pretty complex grids by creating a matrix.

m <- matrix(c(1, 0, 1,  3, 2, 3, 2, 0), nrow = 2, ncol = 4)
##set up the plot
layout(m)
## now put out the 3 plots to each layout "panel"
plot(1:10, main = "plot1")
plot(10:1, main = "plot2")
plot(rnorm(10), main = "plot3")

使用 layout.show 来查看每个面板.

Use layout.show to see each panel.

打印出矩阵来看看它是如何工作的:

Print out the matrix to see how this works:

 m
      [,1] [,2] [,3] [,4]
 [1,]    1    1    2    2
 [2,]    0    3    3    0

第一个面板为 1,第二个为 2,以此类推.非面板"为 0.

There are 1s for the first panel, 2s for the second, etc. 0s for the "non-panel".

参见help(layout).

这篇关于在布局中排列图,这是 'par(mfrow =' 无法实现的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆