[R] rotate ylab

Paul Murrell paul at stat.auckland.ac.nz
Tue Jun 12 00:21:00 CEST 2001


> > > I have an expression for the y axis, which I wish to rotate by 90
> > > degrees (so that this label has the same orientation as for the x
> > > axis). Thought the graphical parameter crt (or srt) would do the
> > > but haven't had any joy so far. Any ideas?
> > > (Using Version 1.2.2, linux, redhat 7.0)
> >
> > >From ?par:
> >
> >      las: numeric in {0,1,2,3}; the style of axis labels.
> >
> >           0: always parallel to the axis [default],
> >
> >           1: always horizontal,
> >
> >           2: always perpendicular to the axis,
> >
> >           3: always vertical.
> >
> >           Note that other string/character rotation (via  `par(srt =
> >           ..)') does not affect the axis labels.
> Cheers for the quick reply. However, I found when I used las that although
> it changed the orientation of the axis labels (ie the numbers on the axis
> tickmarks), it didn't change the orientation of the x- and y axis titles,
> ie the expressions which I passed to xlab and ylab with the plot command:
> plot(alpha,sigma,xlab=expression(alpha),ylab=expression(sigma))

The drawing of xlab and ylab ignores the par(las) setting.  This may seem
like an annoying thing for plot() to do, but there two points to make in its

(i)  plot() is a high-level function designed to try and provide sensible
default behaviour (and not to be too ridiculously complicated).  In the case
of drawing ylab and xlab, the only sensible (simple) general solution is to
draw them parallel to the axes because they can be very long and would
otherwise disappear off the edge of the plot or impinge on the plot data

(ii)  you can override this "sensible" default behaviour if it annoys you.
For example, you can stop plot() drawing xlab and ylab by something like
plot(ann=F) or plot(xlab="", ylab="") AND you can draw them yourself using
mtext(), which does listen to par(las).
A couple of examples of what I mean ...

    par(mfrow=c(2,2), mar=c(5.1, 4.1, 4.1, 2.1), las=0)
    plot(0:10, 0:10, type="n")
    text(5, 5, "The default axes")
    box("figure", lty="dashed")
    plot(0:10, 0:10, type="n")
    text(5, 5, "The user says horizontal text please\n\nbut R knows better
    box("figure", lty="dashed")
    par(las=1, mar=c(5.1, 6.1, 4.1, 2.1))
    plot(0:10, 0:10, type="n", ann=F)
    mtext("0:10", side=2, line=3)
    mtext("0:10", side=1, line=3)
    text(5, 5, "The user fights back !")
    box("figure", lty="dashed")

Anyway, whether you needed the philosophy or not, I hope that helps with
your example :)


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