[R] axis function

Prof Brian D Ripley ripley at stats.ox.ac.uk
Fri May 26 08:50:37 CEST 2000


On Thu, 25 May 2000, Ben Bolker wrote:

> On Thu, 25 May 2000 zivan.karaman at limagrain.com wrote:
> 
> > In S-PLUS, the 'axis' function accepts some arguments that don't exist
> > in the R counterpart.
> > 
> > The two that I'm interested in right now are 'pos' and 'ticks'.
> > 
> > Any suggestions on how obtain the same result with R?
> > 
> 
> Good news and bad news.
> The good news: you can pass any graphics parameter to 'axis', including
> "tck" (tick length--if set to zero this eliminates ticks) and "mgp" (which
> is a three-place vector that sets the position of axis title, labels, and
> lines respectively).
> 
> The bad news: only the second element of mgp (label position) seems to
> have any effect (R 1.0.0, RH 6.0).  This looks like a couple of bugs ...

pos has nothing to do with mgp: it is the position on the plot in user
coordinates. Bill Venables reported it as lacking to R-bugs a little while
ago. The problem is that the current R code has hard-coded the axis labels
to be in the margins, not in the plot area itself.  pos is used to, for
example, put an axis in the middle of a plot region. For example

plot(c(0,1),c(-0.5,,1),axes=FALSE, xaxs="i")
axis(side=1, pos=0)
axis(side=2)

in S puts an axis at y=0.

> ## examples
> 
> par(mfrow=c(2,2))
> ## ticks on y-axis but not x-axis
> plot(c(0,1),c(0,1),axes=FALSE)
> axis(side=1,tck=0)
> axis(side=2)

That is not what ticks=F does, either. It omits the axis line too and just
plots the labels.

plot(c(0,1),c(0,1),axes=FALSE)   
axis(side=1, ticks=FALSE)

gives an axis with 0.0  ...  1.0  and nothing else.

> ## attempt to move x-title in toward plot, doesn't work
> plot(c(0,1),c(0,1),axes=FALSE)
> axis(side=1,mgp=c(1,1,1),labels=FALSE)
> axis(side=2,lwd=2)

That's not a bug. It is plot not axis that puts the x-title on. Try

plot(c(0,1),c(0,1),axes=FALSE, mgp=c(1,1,1))
axis(side=1,mgp=c(1,1,1),labels=FALSE)
 
> ## move x-labels away from plot
> plot(c(0,1),c(0,1),axes=FALSE)
> axis(side=1,mgp=c(1,4,1))
> axis(side=2,lwd=2)
> 
> ## try to move x-axis line, doesn't work
> plot(c(0,1),c(0,1),axes=FALSE)
> axis(side=1,mgp=c(1,1,4))
> axis(side=2,lwd=2)

True.  In S that can also be done by argument line, that moves the axis
as a whole (including ticks and labels), and mgp[3] measures the
displacement from the line as moved by line=foo.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list