R中布局的使用

Dar*_*rko 0 plot r

我正在尝试为此图创建此布局:

layout(matrix(c(1,1,1,1,1,1,
                2,2,2,3,3,3,
                2,2,2,3,3,3,
                2,2,2,3,3,3), nrow=4,ncol=6,byrow = TRUE))

# Set up the top chart that keeps track of the current frame/iteration
# Dress it up a little just for fun
plot(-5, xlim = c(1997,2011), ylim = c(0, .3), xlab = "", ylab = "", main = "Time",axes=F)
abline(v=1995, lwd=5, col = rgb(0, 0, 255, 255, maxColorValue=255))

# Bring back the X axis
xticks <- 1997:2011
axis(side=1, at=xticks, labels=xticks)

# Plot
plot(1:100,1:100)
plot(1:100,1:100)
Run Code Online (Sandbox Code Playgroud)

显然,后两个图不在 plot(1:100,1:100)我的真实代码中,但是我对的用法有疑问layout。为什么我在第一个情节上出现此错误?

Error in plot.new() : figure margins too large
Run Code Online (Sandbox Code Playgroud)

我希望第一张照片有点高

Jea*_*lie 5

听起来可能很愚蠢,但其原因确实是图边距太大!

让我详细说明一下。在R中,有几种边距可让您的图片呼吸:

图片来源http://research.stowers-institute.org/mcm/efg/R/Graphics/Basics/mar-oma/index.htm

在您的特定情况下,由于您尝试在同一图中填充太多图形,因此边际正在吞噬所有可用空间。

为了解决这个问题,我建议将所有边距设置为0:

par(mai=c(0,0,0,0), oma=c(0,0,0,0), mar=c(0,0,0,0))
Run Code Online (Sandbox Code Playgroud)

这可能会导致您的绘图至少被渲染。同时,所有子图之间的距离太近,因此您必须一点一点地增加边距,并进行类似的调用,par(...)直到结果看起来不错为止。

希望这可以帮助 :)