[R] GGPLOT: Superscript text in body of plot
ru|pb@rr@d@@ @end|ng |rom @@po@pt
Sat Jan 29 21:04:20 CET 2022
Here is a way.
ggplot(jjdata, aes(x=x, y=y))+
geom_text(x=3, y=7.5, label=expression(paste(R^2 == '0.23')))
Hope this helps,
Às 19:32 de 29/01/2022, Sorkin, John escreveu:
> Can you help me create text that has a superscript 2?
> I am trying to add text within the body of a plot created with ggplot. I what the text to R-squared = 0.23. I want R-squared to be shown in standard notation, i.e. capital R followed by a super-script 2 and then =0.23 as standard (i.e. non-superscripted text). I have tried the follow, but it does not work:
> jjdata <- data.frame(x=1:10,y=1:10)
> ggplot(jjdata, aes(x=x, y=y))+
> geom_text(x=3, y=7.5, label='R^2=0.23')
> The result I get follows the text of the label argument perfectly. The carrot (^) is included in the printed text; it is not interpreted as a command to set the 2 as a superscript. How do I make the 2 into a superscript?
> Thank you,
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help