Search code examples
rggplot2plotmath

Better solution regarding annotation in ggplot?


I have the following code

     standard_text = "(%)"
    plotmath_text <- "I^2"
    g <- ggplot(data=data.frame(x=0,y=0))+geom_point(aes(x=x,y=y))
g+ annotate("text", x = 4.3, y = 6.97, label =standard_text)+
 annotate("text",x = 4, y = 7, cex = 7, label = plotmath_text,parse = TRUE )

That produces a graph where in its upper right corner has the annotation

I^2 (%)

Is there any way to create the same annotation using just annotate command once instead of two? I have tried to merge them into one command following that page but I was always getting errors.


Solution

  • annotate("text", x = 4, y = 7, cex = 7, label = "I^2 ~ ('%')", parse = TRUE)
    

    enter image description here

    UPD: related questions: one, two.