[R] Using plotmath expressions in lattice key text

Bert Gunter gunter.berton at gene.com
Thu Nov 15 20:12:45 CET 2007


Folks:

delta <- 1:5

I would like to put 5 separate lines of text of the form "10 %+-% delta[i]"
into a lattice key legend, where ""%+-%" is the plotmath plus/minus symbol
and delta[i] is the ith value of delta.

The construct:

lapply(delta,function(d)bquote(10%+-%.(d)))

appears to produce a list of expressions of the correct form, and, indeed,
if I assign the above to (a list!) test,

plot(0:1,0:1)
text(.5,.5,test[[1]])

produces the correctly formatted plotmath expression. However, note that I
have to use test[[1]] to extract the expression; test[1] doesn't work (it is
a list containing an expression, not an expression) -- and therein may lie
the problem. For if I try to use the above expression as the lab component
of the text component in key, e.g. by

xyplot(....,
key = list( text = list(lab =
lapply(delta,function(d)bquote(10%+-%.(d))),...),...)


I get an error:

Error in fun(key = list(text = list(lab = list(10 %+-% 1, 10 %+-% 2 : 
  first component of text has to be vector of labels


So how should I do this?? I suspect it's simple, but I just can't figure it
out.

Note: I'd be happy to supply reproducible code if needed. Just complain and
I'll do so.

Thanks.


Bert Gunter
Genentech Nonclinical Statistics



More information about the R-help mailing list