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
Bert Gunter said the following on 11/15/2007 1:12 PM:> 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 StatisticsHi, Bert, This is how I've done it in the past. Perhaps there's a better way: library(lattice) delta <- 1:5 expr <- paste("10%+-%", delta, sep = "", collapse = ",") expr <- paste("expression(", expr, ")", sep = "") expr <- eval(parse(text = expr)) xyplot(0 ~ 0 | factor(delta), key = list(text = list(expr)), ## bonus: adding it to the strip strip = function(factor.levels, ...) { strip.default(factor.levels = expr, ...) }) Thanks, --sundar
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 > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >