Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 985
Nick Avatar asked Feb 21 '26 17:02

Nick


1 Answers

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

enter image description here

UPD: related questions: one, two.

like image 195
tonytonov Avatar answered Feb 23 '26 09:02

tonytonov