[R] I want axes that cross

Paul Johnson pauljohn32 at gmail.com
Fri Feb 13 20:25:32 CET 2009


Hello, everybody.

A student asked me a howto question I can't answer.  We want the
length of the drawn axes to fill the full width and height of the
plot, like so:

   |
   |         *
   |           *
   |     *
---|-----------------

However, when we use plot with axes=F and then use the axis commands
to add the axes, they do not cross over each other. We get


   |         *
   |           *
         *
       ----------

The axes are not wide enough to cover the entire range of the data. We
do not want to add a box() command, which is a usual answer for this,
because we don't want to draw on top or the side.

Here's my test case:

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")

Can I cause the 2 axes to "cross" as desired?

The axis help says the axis is clipped at the plot region, but it
seems to get clipped even more narrowly thanthat.

I've been searching in r-help quite a bit and am a little surprised
how difficult this is....

-- 
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas




More information about the R-help mailing list