[R] Math expression with object to evaluate

Gabor Grothendieck ggrothendieck at gmail.com
Fri Dec 22 13:25:40 CET 2006


Use bquote:

ID <- 3
plot(1,1, main = bquote(ID ~ is ~ .(ID)))

Also please read the last line of every message to r-help regarding
reproducible examples.  (None of your variables were defined.)

On 12/22/06, KKThird at Yahoo.Com <kkthird at yahoo.com> wrote:
> Hello.
>
> I have a question that probably has a simple answer.
>
> I have a loop where several figures are plotted with each iteration. I calculate some descriptives to put in the title of the figure. When I use expression, since I want to combine math plotting symbols and the descriptives I calculate, I get an error. Here is an example of the code that I tried:
>
> plot(x,y, main=expression(paste("ID is", ID.i, italic(R)^2, r2.i, "RMSE", error.i)))
>
> where ID.i, r2.i, and error.i change for each iteration of the loop. I suppose the problem is that expression does not know to treat each of these as objects rather than part of a mathematical expression. Is there a way to display the value of ID.i, r2.i, and error.i within the expression?
>
> Thanks for any thoughts,
> Ken
>
>  __________________________________________________
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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