[R] expressions as axis labels
Uwe Ligges
ligges@statistik.uni-dortmund.de
Sun, 26 May 2002 10:34:48 +0200
[moved to R-devel]
Thomas Lumley wrote:
>
> On Sat, 25 May 2002, Patrick Buetzberger wrote:
>
> > Dear colleagues,
> >
> > I often use chemical formulas to label my x-axis, e.g. in barplots. I
> > used to do this like the following example and it worked just fine:
> >
> <snip>
> >
> > The important point is the x-axis here: before we installed the new R
> > 1.5 on our workstations, the chemical formulas were properly aligned and
> > looked well. Ever since, if I use the exact same procedure, I get the
> > graphic but the chemical formulas are not aligned horizontally properly
> > anymore: e.g. Mg^{2+''} or NO[3]^{-''} are a bit higher than F^{-''} or
> > H^{+''} (it seems to depend on whether there is a subscript or a letter
> > with a part below the main line like a 'g').
> > I didin't find any hint on the r-project homepage. I don't know if we
> > forgot some feature when newly installing R or if something changed in
> > version 1.5.
>
> I think something changed. In the NEWS file we have
>
> o The vertical alignment of mathematical annotations was wrong.
> When a vertical adjustment was not given, it was bottom-adjusting
> i.e,. it was treating adj=0 as adj=c(0, 0). It now treats
> adj=0 as adj=c(0, 0.5) as for "normal" text. (PR#1302)
>
> and I expect this is responsible.
That change indeed is reasonable, but I don't think it is this
particular change (at least as documented) that makes Patrick's example
doesn't work any more.
> It looks to me as if R is now trying to center the expressions vertically.
Right for text() and friends, but not for axis(), see the example below,
and maybe this is a bug (Paul?). Anyway, fixing this bug (?) won't
change much for Patrick's example.
> This is also consistent with the previous reply that suggested putting blank
> subscripts on everything as a work-around.
If sub- or superscripts are a expression, space is added below
respective above that expression (if not already done before), so
complex formulas can be generated. And, at least for me, the result is
somehow expected.
I am very surprised and wondered why Patrick's example worked in
R-1.4.1.
Without having looked into the code, there must have been something
fuzzy that is broken since R-1.5.0.
> I don't think there's a complete fix for this, since sometimes people want
> expressions aligned on their actual vertical centers and sometimes on the
> center of the main line of text (as you do).
Here an example on the alignments:
plot(1:12, type="n", axes=FALSE)
expr <- expression(F^{-''}, Cl^{-''}, NO[2]^{-''}, NO[3]^{-''},
PO[4]^{3-''}, SO[4]^{2-''}, Na^{+''}, NH[4]^{+''}, K^{+''},
Mg^{2+''}, Ca^{2+''}, H^{+''})
axis(1, 1:12, lab=expr) # the "problem"
text(1:12, 3, expr) # adj=c(0.5, 0.5), the default for text()
# This looks like the x-axis annotation:
text(1:12, 5, expr, adj=c(0.5, 0))
# And this is all in *one* formula, as Patrick would like to get it
somehow.
# Only a guess: Was there something like a "coerce to one formula" in
R-1.4.1?
text(6, 9,
labels = expression(F^{-''} * Cl^{-''} * NO[2]^{-''} * NO[3]^{-''} *
PO[4]^{3-''} * SO[4]^{2-''} * Na^{+''} * NH[4]^{+''} * K^{+''} *
Mg^{2+''} * Ca^{2+''} * H^{+''}))
I am sure, Paul will get the point in less than a second.
Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._