Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Annotate with greater than or equal to in ggplot

I want to annotate a ggplot with the phrase "Large fish ≥ 45cm" but can't seem to achieve it. I tried the following example but it produces an "=". Also adding "45" throws up an error.

ggplot(mtcars, aes(mpg, disp))+
geom_point()+
annotate("text",25,400, label=("Fish*~symbol('\u2265')*~cm"), parse=TRUE, hjust=0) 
like image 931
jimken Avatar asked Dec 29 '25 05:12

jimken


2 Answers

How about this:

ggplot(mtcars, aes(mpg, disp))+
    geom_point()+
    annotate("text",25,400, label=("'Large fish' >= 45 ~ 'cm'"), parse=TRUE, hjust=0)
like image 64
mt1022 Avatar answered Dec 30 '25 18:12

mt1022


A different solution is based on the latex2exp package (an R package that parses and converts LaTeX math formulas to R’s plotmath expressions):

library(latex2exp)
ggplot(mtcars, aes(mpg, disp))+
 geom_point()+
 annotate("text",25,400,
          label=TeX("Fish $\\geq$ 45 cm", output="character"),
          hjust=0, parse=TRUE)
like image 34
Marco Sandri Avatar answered Dec 30 '25 20:12

Marco Sandri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!