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]]
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.
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. >