X and Y axis intersect at 0 [duplicate]

2020-04-17 08:10发布

I have used the following code to generate this plot:

x<-c(0.916,  0.815, 0.101, -0.029, -0.166, 0.949, 0.073 , -0.054, 1.006)
y<-c(3.91, 5.17, 1.08, 1.28, 1.01, 4.37, 3.97, 0.77, 4.52)
plot(x,y, ylim=c(0, 8), xlim=c(-0.4, 1.2), pch=19, cex=0.6, cex.axis=1, cex.lab=1, yaxs='i', xaxs='i', las=1, bty="l")

I want the x and y to intersect at 0, I have tried using axes=FALSE and trying with axis function but does not work. It would be great to help me with that, thanks!

This is the way I tried to do it:

plot(x,y, xlim=c(-0.5, 1.2), axes=FALSE, pch=19)
axis(1, pos=0)
axis(2, pos=0, at=0:8)

and here is the weird looking plot!enter image description here

enter image description here

标签: r
1条回答
对你真心纯属浪费
2楼-- · 2020-04-17 08:23

enter image description here

plot(x,y, xlim=c(-0.5, 1.2), axes=FALSE, pch=19, ylim=c(0,8))
axis(1, pos=0)
axis(2, pos=0, at=0:8, labels=c("",1:8) )

The trick needed to get the axis(2,...) call to construct a line that made it all the way to (0,0) was to add the ylim argument. Otherwise the plot area was not large enought to support the range of axis values that you asked for.

查看更多
登录 后发表回答