I need it to look like this:
R^2 = some values
And I've tried the code below but it wouldn't work, it came out as "R (expression (^2)) = some values" instead:
text (25, 200, paste ("R (expression (^2)) =", round (rsquarelm2, 2)))
I need it to look like this:
R^2 = some values
And I've tried the code below but it wouldn't work, it came out as "R (expression (^2)) = some values" instead:
text (25, 200, paste ("R (expression (^2)) =", round (rsquarelm2, 2)))
The
paste
function returns a string, not an expression. I prefer to usebquote
for cases like this:You don't want a character vector, but an expression, hence this
is what you need. In this case, you want to substitute in the result of another R operation. For that you want
substitute()
orbquote()
. I find the latter easier to work with:With
bquote()
, anything in.( )
is evaluated and the result is included in the expression returned.How to include formatting and mathematical values in plots is FAQ 7.13.
demo(plotmath)
is also useful.In this case, you can use either
or
(
format
is more appropriate here thanround
, since you want to control how the value is displayed rather than creating an approximation of the value itself.)