在 R 中以 2-1 布局绘制 3 个图形 [英] Plotting 3 graphs in a 2-1 layout in R

查看:57
本文介绍了在 R 中以 2-1 布局绘制 3 个图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 R 中的单个图中获得 3 个图,其分布如下图所示?绘图必须具有相同的宽度,并且绘图 C 应居中.

Is it possible to obtain 3 plots in a single figure in R with a distribution as shown in the image below? The plots must have the same width, and plot C should be centered.

-----   -----
| A |   | B |
-----   -----
    -----
    | C |
    -----

谢谢!

推荐答案

是的,使用 layout(...) 函数.

layout(matrix(c(1,2,3,3), 2, 2, byrow = TRUE))
hist(mtcars$wt)
hist(mtcars$mpg)
hist(mtcars$disp)

所以 layout(...) 采用一个矩阵,其中每个元素对应一个绘图编号.在这种情况下,[1,1] 对应于第一幅图,[1,2] 对应于第二幅图,而 [2,1:2] 对应于第三幅图.

So layout(...) takes a matrix where each element corresponds to a plot number. In this case, [1,1] corresponds to the first plot, [1,2] corresponds the the second plot, and [2,1:2] corresponds to the third plot.

此示例取自此处,稍作修改.

This example is taken with slight modification from here.

如果您希望底部图与上面两个图具有相同的宽度",您可以调整该图的边距.

If you want the bottom plot to be the same "width" as the two above, you can tweak the margins for that plot.

par(mar=c(4,4,2,2))
layout(matrix(c(1,2,3,3), 2, 2, byrow = TRUE))
hist(mtcars$wt)
hist(mtcars$mpg)
par(mar=c(2,14,2,14))
hist(mtcars$disp)

这篇关于在 R 中以 2-1 布局绘制 3 个图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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