R图形:在图表上使两个图更接近

时间:2012-02-11 09:09:24

标签: r plot

我有一个用代码制作的图表:

yvalue = c(100, -100, 50, 0)
xvalue = c(1, 1, 2, 2)
gmin = c(-100, 0)
gmax = c(100, 50)
xarrow = c(1, 2, 3, 4)
gplot = plot(xvalue, yvalue, xaxt="n", main="Just a graph", xlab="Groups", ylab="y-value")
xvaluenames = c("Group 1", "Group 2", 1, 2)
axis(1, at = 1:length(xvalue), labels = xvaluenames)
arrows(x0=xarrow, y0=gmin, x1=xarrow, y1=gmax, length=0)
abline(h=0)

Graph

我希望第1组和第2组图更紧密。更像是:

Better Graph

有没有人建议如何让它们更接近?

1 个答案:

答案 0 :(得分:3)

作为graph()来电的附加参数,您可以添加:xlim = c(x1,x2),其中x1x2是可见x轴的限制。

在您的情况下,由于您使用的是x-coords 12,因此您可以使用xlim=c(0.5,2.5)

enter image description here