[R] Combining expressions and objects within labels

Paul Murrell p.murrell at auckland.ac.nz
Sun Nov 14 22:31:16 CET 2004


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/




More information about the R-help mailing list