[R] variable values in plotmath expressions
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Mar 16 04:45:37 CET 2012
On Thu, Mar 15, 2012 at 10:25 PM, Richard M. Heiberger <rmh at temple.edu> wrote:
> ## I would like help in using variable values in plotmath expressions
> ## in lattice
>
> x <- 1:10
> y <- 1:10
> pval <- .95
>
> plot(y ~ x, ## works as I want in base graphics
> main=substitute(list(alpha * " = " * group("",list(p),"")),
> list(p=pval)))
>
> plot(y ~ x, ## doesn't work as intended: "pval" is displayed
> main=substitute(list(alpha * " = " * group("",list(pval),""))))
>
> try( ## doesn't work: object 'alpha' not found
> xyplot(y ~ x,
> main=substitute(list(alpha * " = " * group("",list(p),"")),
> list(p=pval)))
> )
>
> xyplot(y ~ x, ## doesn't work as intended: "substitute" is displayed
> main=expression(substitute(list(alpha * " = " * group("",list(p),"")),
> list(p=pval))))
>
> xyplot(y ~ x, ## doesn't work as intended: "p" is displayed and "pval" is
> displayed
> main=expression(list(alpha * " = " * group("",list(p),"")),
> list(p=pval)))
>
> xyplot(y ~ x, ## doesn't work as intended: "pval" is displayed
> main=expression(list(alpha * " = " * group("",list(pval),""))))
Try bquote with classic graphics or as.expression(bquote(...)) with lattice:
plot(y ~ x, main = bquote(alpha == .(pval)))
xyplot(y ~ x, main = as.expression(bquote(alpha == group("", .(pval) ,""))))
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list