Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

geom_text(), plotmath, and %

I want to add "R^2 = 70%" to my plot using geom_text() (where ^ indicates a superscript).

Without the % sign, it's easy:

my.data <- data.frame(x=1:5, y=1:5)
p1      <- ggplot(my.data, aes(x=x, y=y)) + geom_point()
p1      <- p1 + geom_text(x=2.5, y=5, label="R^2 == 70", parse=TRUE)
p1

Adding % is trickier than expected. I managed to get it by adding a second geom_text() statement:

p1 <- p1 + geom_text(x=2.63, y=4.97, label="%")
p1

How can it be done with a single geom_text() statement?

like image 691
user13424 Avatar asked May 21 '26 18:05

user13424


1 Answers

This works...

geom_text(x=2.5, y=5, label="R^2 == 70*'%'", parse=TRUE)
like image 169
Andrew Gustar Avatar answered May 24 '26 13:05

Andrew Gustar