如何操纵地块之间的边距?

How is the margin between plots manipulated?

我有三组,每组包含一对条形图。我想在每组之间加上space,所以有一些区别。但是,当我通过 par() 中的 mar 参数操作边距时,它会影响条形图的宽度。

par(mfrow=c(1,6))
#pair1 
par(mar=c(5,2,5,1), xpd=TRUE)
barplot(t(cbind(1, 5, 6)), col=c("red", "orange", "yellow"))
par(mar=c(5,2,5,2), xpd=TRUE)
barplot(t(cbind(3, 3, 2)), col=c("blue", "green", "purple"))

#pair2
par(mar=c(5,4,5,1), xpd=TRUE)
barplot(t(cbind(2, 2.5, 5)), col=c("red", "orange", "yellow"))
par(mar=c(5,2,5,2), xpd=TRUE)
barplot(t(cbind(5, 1, 3)), col=c("blue", "green", "purple"))

#pair2
par(mar=c(5,4,5,1), xpd=TRUE)
barplot(t(cbind(4, 2, 1)), col=c("red", "orange", "yellow"))
par(mar=c(5,2,5,2), xpd=TRUE)
barplot(t(cbind(6, 2, 1)), col=c("blue", "green", "purple"))

如何在保持条形图宽度的同时在 3 个图之间添加更多 space?感谢任何建议。

有一个 space 参数。

https://stat.ethz.ch/R-manual/R-patched/library/graphics/html/barplot.html

描述:

the amount of space (as a fraction of the average bar width) left before each bar. May be given as a single number or one number per bar. If height is a matrix and beside is TRUE, space may be specified by two numbers, where the first is the space between bars in the same group, and the second the space between the groups. If not given explicitly, it defaults to c(0,1) if height is a matrix and beside is TRUE, and to 0.2 otherwise.

我建议使用 layout 函数而不是 par(mfrow=c(1,6)) 并将 3 对之间的 space 指定为额外的 "blank" 绘图区域。

这是一个简单的例子:

tmpmat <- rbind(c(1,2,0,3,4,0,5,6))
layout(tmpmat, widths=c(3,3,1,3,3,1,3,3))

barplot(rbind(1,5,6))
barplot(rbind(3,3,2))

barplot(rbind(2,2.5,5))
barplot(rbind(5,1,3))

barplot(rbind(4,2,1))
barplot(rbind(6,2,1))

另一种可能性是将所有向量组合成一个矩阵并创建一个条形图,然后使用 space 参数来控制堆叠条之间的 spaces(我相信这就是@PedroBraz's answer is meant to convey. 这会将所有条形图放在相同的垂直比例尺上,而你和我的示例为每个条形图提供了自己的垂直比例尺。