Skip to content
Prev 170458 / 398506 Next

I want axes that cross

on 02/13/2009 01:25 PM Paul Johnson wrote:
Paul,

I am guessing that you want:

x <- rnorm(100)
z <- gl(2,50)
y <- rnorm(100, mean= 1.8*as.numeric(z))

plot(x,y,type="n", axes=F)
points(x,y, pch="$",cex=0.7, col=z)
axis(1, col="green", col.axis="green")
axis(2, col="red", col.axis="red")

# Draw the box like an "L" on the bottom and left only
box(bty = "l")


Note that you can specify which sides the 'box' is created upon by using
the 'bty' argument. See ?box for more information.

Also, by default, the axes extend the range of 'x' and 'y'  by 4%. You
can use 'xaxs = i' and 'yaxs = i' in the plot() call to restrict the
axes to the true ranges of 'x' and 'y'.  This would be important, for
example, when you want the lower left hand corner of the plot to be at
exact coordinates such as 0,0.

See ?par for more information.

HTH,

Marc Schwartz