From p.murrell@auckland.ac.nz  Wed May 29 01:54:25 2002
From: p.murrell@auckland.ac.nz (Paul Murrell)
Date: Wed, 29 May 2002 12:54:25 +1200
Subject: [R] expressions as axis labels
References: <Pine.A41.4.44.0205251157270.128430-100000@homer17.u.washington.edu> <3CF09E28.8BB7DDC9@statistik.uni-dortmund.de>
Message-ID: <3CF426C1.2F8B2A86@stat.auckland.ac.nz>

Hi

<lots of examples snipped to be replaced by my own ...>

I don't think the current code is performing incorrectly, but its
behaviour may need a bit more explanation.  Here goes ... :)

1.  Here's a demonstration that, using text(), the horizontal and
vertical adjustments of mathematical annotations are done according to
the bounding boxes of the annotations ...

    expr <- expression(F^{-''}, Cl^{-''}, NO[2]^{-''}, NO[3]^{-''}, 
        PO[4]^{3-''}, SO[4]^{2-''}, Na^{+''}, NH[4]^{+''}, K^{+''},
        Mg^{2+''}, Ca^{2+''}, H^{+''})
    plot(1:12, type="n", axes=FALSE)
    box()
    axis(2)
    abline(v=1:12, h=1:12, col="grey")
    y <- 1
    for (xadj in c(0, .5, 1))
      for (yadj in c(0, .5, 1)) {
        text(1:12, y, expr, adj=c(xadj, yadj))
        y <- y+1
      }

... this is a very "graphical" view of these annotations, which makes
some sense when drawing annotations within the data region, but less
sense in the margins.  We probably need to allow the user to choose a
more "textual" alignment based on the "baseline" of the text in the
annotation.  One day ...

2. The mtext() and axis() functions do not allow the user to control
"vertical" adjustment of text -- they determine this adjustment
themselves based on the setting of par(las).  In the example given by
Patrick, where the x-axis labels are horizontal, the tick labels are
bottom-adjusted -- adj=c(<user xadj>, 0) -- relative to the "line" in
the margin that the labels are to be drawn on.  This is comparable to
row 4 in the plot produced above ...

    axis(1, at=1:12, labels=expr)

... In the old code, the tick labels were vertically centred --
adj=c(<user xadj>, 0.5) -- comparable to row 5 in the plot.  Sorry that
my bug fix to correct this "wrong" behaviour broke your example;  I
always worry that this sort of thing will occur when I try to "fix" bits
of the graphics code :(

3.  One "recommended" way to get your example to work would be to place
"phantom" subscripts and superscripts in your labels so that they are
all the same "height".  It's not pretty, but here's an example, ...

    expr <- expression(F[phantom(0)]^{-phantom(0)},
        Cl[phantom(0)]^{-phantom(0)},
        NO[2]^{-phantom(0)}, NO[3]^{-phantom(0)}, 
        PO[4]^{3-phantom(0)}, SO[4]^{2-phantom(0)},
        Na[phantom(0)]^{+phantom(0)},
        NH[4]^{+phantom(0)}, K[phantom(0)]^{+phantom(0)},
        Mg[phantom(0)]^{2+phantom(0)}, Ca[phantom(0)]^{2+phantom(0)},
        H[phantom(0)]^{+phantom(0)})
    plot(1:12, type="n", axes=FALSE)
    box()
    axis(2)
    axis(1, at=1:12, labels=expr)

Hope that helps.

Paul
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[R] expressions as axis labels
Paul Murrell