[R] Math expression with object to evaluate

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Dec 22 08:46:31 CET 2006


You might want to read the "R Help Desk: Automation of Mathematical 
Annotation in Plots" in R News 2 (3), 32-34.
and you will understand that the following works:

plot(x, y, main =
   substitute("ID is" * ID.i * ", " * italic(R)^2 ==
               r2.i * {", RMSE" == error.i},
              list(ID.i = ID.i, r2.i = r2.i, error.i = error.i)))

For the next time, please make your example reproducible as the posting 
guide asks you to do.

Uwe Ligges



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