[R] How to format Rsuperscript 2 followed by = value

Nevil Amos nevil.amos at gmail.com
Mon Oct 3 06:02:28 CEST 2011


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



More information about the R-help mailing list