Skip to content

How to format Rsuperscript 2 followed by = value

2 messages · Nevil Amos, sina.r

#
I am trying to put  an
R2 value with R2 formatted with a superscript 2 followed by "=" and the 
value :
the first mtext prints the R2 correctly formatted but follows it with 
"=round(summary(mylm)$r.squared,3)))" as text
the second prints "R^2 =" followed by the value of 
round(summary(mylm)$r.squared,3))).

how do I correctly write the expression to get formatted r2 followed by 
the value?




x=runif(10)
y=runif(10)
summary(mylm<-lm(y~x))
plot(x,y)
abline(mylm)
mtext(expression(paste(R^2,"=",round(summary(mylm)$r.squared,3))),1)
mtext(paste(expression(R^2),"=",round(summary(mylm)$r.squared,3)),3)



thanks

Nevil Amos
#
Hi Nevil,

the function bquote() should do what you want:
(found here: http://r.789695.n4.nabble.com/expression-td904189.html)

mtext(bquote(R^2==.(round(summary(mylm)$r.squared,3))),1)

Regards,
Sina R?eger

--
View this message in context: http://r.789695.n4.nabble.com/How-to-format-Rsuperscript-2-followed-by-value-tp3866771p3867093.html
Sent from the R help mailing list archive at Nabble.com.