R:layout()影响打印区域中的边距大小

R:layout()影响打印区域中的边距大小,r,plot,R,Plot,我在尝试用不同数量的面板自动生成R中的合成图形时遇到问题。当我的图中有3个或3个以上的面板时,边距明显不同(1x3图中的边距较小),足以导致R不正确地绘制标签并影响整体外观 # plot empty plot with box around plot and figure plot_box <- function() { plot(1, 1, type='n', bty='n', xaxt='n', yaxt='n', xlab='', ylab='') b

我在尝试用不同数量的面板自动生成R中的合成图形时遇到问题。当我的图中有3个或3个以上的面板时,边距明显不同(1x3图中的边距较小),足以导致R不正确地绘制标签并影响整体外观

# plot empty plot with box around plot and figure
plot_box <- function() {
        plot(1, 1, type='n', bty='n', xaxt='n', yaxt='n', xlab='', ylab='')
        box(lwd = 6)
        box("figure", lwd=6, col='red')
}

png("box_test1.png", width=1000, height=500)
par(oma=c(0,0,0,0))
layout(t(1:2))
par(mar=c(3, 3, 3, 3))
plot_box()
par(mar=c(3, 3, 3, 3))
plot_box()
dev.off()

图像在堆栈溢出时缩放显示,但从设备调用中可以看到,它们的大小完全相同


这个问题让我很困惑,老实说感觉就像一个bug,但是我知道R绘图代码非常成熟,所以我希望有一个解决方案。

您正在使用mar设置边距,这是以线条为单位的, 嗯,很难妥善管理

 ‘mar’ A numerical vector of the form ‘c(bottom, left, top, right)’
      which gives the number of lines of margin to be specified on
      the four sides of the plot.  The default is ‘c(5, 4, 4, 2) +
      0.1’.
如果您使用mai,您将获得一致的物理大小

 ‘mai’ A numerical vector of the form ‘c(bottom, left, top, right)’
      which gives the margin size specified in inches.
另请参见本部分:

 The meaning of ‘character size’ is not well-defined: this is set
 up for the device taking ‘pointsize’ into account but often not
 the actual font family in use.  Internally the corresponding pars
 (‘cra’, ‘cin’, ‘cxy’ and ‘csi’) are used only to set the
 inter-line spacing used to convert ‘mar’ and ‘oma’ to physical
 margins.  (The same inter-line spacing multiplied by ‘lheight’ is
 used for multi-line strings in ‘text’ and ‘strheight’.)

为什么它一定是一个bug?另外,看看
lattice
ggplot2
软件包。我知道其他绘图软件包,但我使用基本图形生成绘图(基本上是大型阵列上的image())。我之所以说这是一个bug,是因为边距被指定为文本行的倍数,并且应该与总打印大小保持不变(显然比例会改变)。
 The meaning of ‘character size’ is not well-defined: this is set
 up for the device taking ‘pointsize’ into account but often not
 the actual font family in use.  Internally the corresponding pars
 (‘cra’, ‘cin’, ‘cxy’ and ‘csi’) are used only to set the
 inter-line spacing used to convert ‘mar’ and ‘oma’ to physical
 margins.  (The same inter-line spacing multiplied by ‘lheight’ is
 used for multi-line strings in ‘text’ and ‘strheight’.)