3

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

Lucia
  • 901
  • 1
  • 11
  • 16
  • 2
    See here : http://stackoverflow.com/questions/14539785/how-to-place-the-intercept-of-x-and-y-axes-at-0-0-and-extend-the-x-and-y-axe/14540014#14540014 – juba Sep 26 '13 at 14:25
  • Yes, I have already tried that but the x and y do not intersect. – Lucia Sep 26 '13 at 14:34
  • Can you show the code and plot for your other attempt? – beroe Sep 26 '13 at 14:39
  • I just added my attempt! – Lucia Sep 26 '13 at 14:44
  • what's wrong with the result (of your attempt) - don't they intersect at 0? - axis(1); axis(2, pos=0) #maybe a little more beautiful if you omit the at argument – lebatsnok Sep 26 '13 at 14:50
  • yes, I want them to actually meet each other the two axes but they don't, I omit the "at" argument and it stays the same! – Lucia Sep 26 '13 at 14:53

1 Answers1

1

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.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Perfection is usually acknowledged with a checkmark. It also helps other potential answerers see that they search elsewhere for open questions. – IRTFM Sep 26 '13 at 15:20
  • I use this for the y axis:axis(2, pos=0, at=axTicks(2,axp=c(0,8,4)), las=1) instead of your code: axis(2, pos=0, at=0:8, labels=c("",1:8) ) as I want the interval of 2 between my axis labels but the great thing about your code is that it omits the 0 of the y axis. Is there any way to combine this two? thanks in advance! – Lucia Sep 26 '13 at 15:37
  • Use: at=seq(0,8,by=2), labels=c("", 2,4 ,6,8) – IRTFM Sep 26 '13 at 18:55