3

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) 
jimken
  • 117
  • 1
  • 7

2 Answers2

5

How about this:

ggplot(mtcars, aes(mpg, disp))+
    geom_point()+
    annotate("text",25,400, label=("'Large fish' >= 45 ~ 'cm'"), parse=TRUE, hjust=0)
mt1022
  • 16,834
  • 5
  • 48
  • 71
1

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)
Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
  • ggplot returns exactly $\geq$ and in the pdf from Latex it's also $\geq$. How to make it to display ≥? – Laura Nov 25 '19 at 15:08
  • I specifically want to write "≥" symbol in a label of the legend. – Laura Nov 25 '19 at 16:44
  • @Laura You can use the solution proposed here https://stackoverflow.com/questions/19507742/using-expressionpaste-to-insert-math-notation-into-a-legend – Marco Sandri Nov 25 '19 at 17:25