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)))
To indicate a subscript, use the underscore _ character. To indicate a superscript, use a single caret character ^ . Note: this can be confusing, because the R Markdown language delimits superscripts with two carets.
Apply superscript or subscript formatting to text Select the character that you want to format as superscript or subscript. On the Home tab, in the Font group, pick the Font Dialog Box Launcher. On the Font tab, under Effects, select the Superscript or Subscript check box.
The <sup> tag defines superscript text. Superscript text appears half a character above the normal line, and is sometimes rendered in a smaller font. Superscript text can be used for footnotes, like WWW. Tip: Use the <sub> tag to define subscript text.
To produce text in superscript, use a caret followed by the text you want in superscript in curly brackets. To write text as a subscript, use an underscore followed by the text in curly brackets. The symbol "&" on its own is used as part of a code in LaTeX.
You don't want a character vector, but an expression, hence this
expression(R^2 == 0.85)
is what you need. In this case, you want to substitute in the result of another R operation. For that you want substitute()
or bquote()
. I find the latter easier to work with:
rsquarelm2 <- 0.855463
plot(1:10, 1:10, type = "n")
text(5, 5, bquote(R^2 == .(round(rsquarelm2, 2))))
With bquote()
, anything in .( )
is evaluated and the result is included in the expression returned.
The paste
function returns a string, not an expression. I prefer to use bquote
for cases like this:
text(25, 200, bquote( R^2 == .(rs), list(rs=round(rsquarelm2,2))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With