[R] Using plotmath expressions in lattice key text
Deepayan Sarkar
deepayan.sarkar at gmail.com
Fri Nov 16 05:02:12 CET 2007
On Nov 15, 2007 7:12 PM, Bert Gunter <gunter.berton at gene.com> wrote:
>
> 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.
as.expression(lapply(delta, ...))
seems to produce the right sort of vector.
-Deepayan
>
> Note: I'd be happy to supply reproducible code if needed. Just complain and
> I'll do so.
>
> Thanks.
>
>
> Bert Gunter
> Genentech Nonclinical Statistics
>
> ______________________________________________
> R-help at 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.
>
More information about the R-help
mailing list