Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R绘图:使两个绘图在图形上更接近_R_Plot - Fatal编程技术网

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

R绘图:使两个绘图在图形上更接近,r,plot,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

我用代码制作了一个图表:

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)

我希望第1组和第2组的图更接近。更像:


有人对如何使它们更接近有建议吗?

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

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


更改x值并在plot()中设置xlim参数。另外,由于没有箭头,只需使用segments()@tim riffe,我在plot()中添加了type=“n”,因为我只需要这些条。