Skip to content

Combining expressions and objects within labels

2 messages · Jose A. Hernandez, Paul Murrell

#
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)))
#
Hi
Jose A. Hernandez wrote:
text(60, 28, substitute(paste("Pseudo ", r^2 == r_2), list(r_2=r_2)))

Paul