Jose A. Hernandez
2004-Nov-14 20:01 UTC
[R] Combining expressions and objects within labels
Hello all, I am an R novice and I have a simple question and hope somebody can help me out. I need to place several labels in a plot, this labels are some kind of text and also some objects (which come from some more complicated R calculations). In one of this labels I'd like to place a superscript, however I cannot find a way to place both the expression and the object in the same label. Thanks in advance and best regards. Please look at the example below: # my objects eonr <- 75 yldeonr <- 150 r_2 <- 0.95 # the plot and simple labels plot(0:100, 0:100) text(60,40, paste("EONR=",eonr)) text(60,36, paste("Yield at EONR=",yldeonr)) # I'd like to place the superscript on the r text(60,32, paste("Pseudo r^2=",r_2)) # This does not seem to work ... I can get the subscript # but now I cannot paste the r_2 object. Any ideas ? text(60,28, expression(paste("Pseudo r" ^2, "=" r_2))) -- Jose A. Hernandez Department of Soil, Water, and Climate University of Minnesota 1991 Upper Buford Circle St. Paul, MN 55108 Ph. (612) 625-0445, Fax. (612) 625-2208
Hi Jose A. Hernandez wrote:> Hello all, > > I am an R novice and I have a simple question and hope somebody can help > me out. > > I need to place several labels in a plot, this labels are some kind of > text and also some objects (which come from some more complicated R > calculations). > > In one of this labels I'd like to place a superscript, however I cannot > find a way to place both the expression and the object in the same label. > > Thanks in advance and best regards. > > Please look at the example below: > > # my objects > eonr <- 75 > yldeonr <- 150 > r_2 <- 0.95 > > # the plot and simple labels > plot(0:100, 0:100) > text(60,40, paste("EONR=",eonr)) > text(60,36, paste("Yield at EONR=",yldeonr)) > > # I'd like to place the superscript on the r > > text(60,32, paste("Pseudo r^2=",r_2)) > > # This does not seem to work ... I can get the subscript > # but now I cannot paste the r_2 object. Any ideas ? > > text(60,28, expression(paste("Pseudo r" ^2, "=" r_2)))text(60, 28, substitute(paste("Pseudo ", r^2 == r_2), list(r_2=r_2))) Paul -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/