On Sat, 2005-10-01 at 20:32 +1000, John Maindonald wrote:
> expression() accepts multiple expressions as arguments, thus:
> 
> plot(1:2, 1:2)
> legend("topleft",
>                expression(y == a * x^b,
>                                     "where "* paste(y=="wood; ",  
> x=="dbh")))
> 
> Is there a way to do this when values are to be substituted
> for a and b? i.e., the first element of the legend argument
> to legend() becomes, effectively:
>    substitute(y == a * x^b, list(a = B[1], b=B[2]))

John,

Try this:

a <- 5
b <- 3

L <- list(bquote(y == .(a) * x^.(b)),
          "where y = wood; x = dbh")

plot(1:2, 1:2)

legend(legend = do.call("expression", L),
       "topleft")


Note the creation of the list 'L', which uses bquote() and then
the .(Var) construct, where 'Var' are your variables to be replaced.
Then in the legend() call, the use of do.call() to apply expression() to
the elements of list 'L'.

HTH,

Marc Schwartz

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to