如何调整图形之间的边距?

3

我有三组数据,每组数据都包含一对条形图。我想在每组数据之间添加空白以便区分它们。然而,当我通过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个绘图之间的空间?感谢任何建议。

2个回答

3
我建议使用layout函数代替par(mfrow=c(1,6)),并指定3对之间的空格作为额外的“空白”绘图区域。
以下是一个简单的例子:
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参数来控制堆叠条之间的间距(我认为这就是@PedroBraz答案意图传达的内容)。这将使所有条形图在同一垂直比例尺上,而您和我的示例则为每个条形图提供了自己的垂直比例尺。

感谢您的引导。谢谢。 - Jay

1

有一个space参数。

see 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.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接