Hi

Thomas Zumbrunn wrote:
Dear R users

I have problems horizontally aligning labels in keys of lattice plots when the labels make use of plotmath. Here's a self-contained example:

dat <- data.frame(x = rnorm(10),
                  y = rnorm(10),
                  z = factor(rep(c("a", "b"), each = 5)))
xyplot(y ~ x, dat, groups = z,
       auto.key = list(columns = 2,
         text = c(expression(plain("alright")),
           expression(italic("too low")))))

It seems like the grid object which the lattice function creates from the key arguments has different heights for the two labels since the second label does not stretch over the baseline.


I think the basic problem here is that mathematical expressions work with the limits of bounding boxes rather than an overall baseline. A workaround is to use phantom() within the expression to introduce elements with a consistent height that are not actually drawn. For example ...

xyplot(y ~ x, dat, groups = z,
       auto.key = list(columns = 2,
         text = c(expression(plain("alright")*phantom("hg")),
           expression(italic("too low")*phantom("hg")))))

... which forces both expressions to go as high as the top of an "h" and as low as the bottom of a "g" without those characters being drawn (although space is allowed for those characters so you get a bit of blank horizontal space).

Paul


Any ideas how I could circumvent the problem (other than manipulating the key grob)?

Best wishes
Thomas Zumbrunn

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to