Axis position in R scatterplot

HEnav picture HEnav · Jun 17, 2011 · Viewed 9.1k times · Source

I'm trying to create a simple scatter plot in R, where the x-axis range is -10:10, and to re-locate the y axis to the x=0 point. This seems like a fairly basic operation, but I found no way to do that... Thanks for any help!

Answer

Marek picture Marek · Jun 17, 2011
x <- runif(50, -10, 10)
y <- runif(50, -10, 10)
plot(x, y, yaxt="n") # don't plot y-axis, see ?par, section xaxt
axis(2, pos=0) # Draw y-axis at 0 line

x-axis on 0 line

But personally I think that you should use grid() or Andrie solution.