[R] GGPLOT: Superscript text in body of plot

Sorkin, John j@ork|n @end|ng |rom @om@um@ry|@nd@edu
Sat Jan 29 20:32:10 CET 2022


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)
jjdata
ggplot(jjdata, aes(x=x, y=y))+ 
  geom_point(size=2,shape=1)+
  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,
Joh


More information about the R-help mailing list