Annotate with greater than or equal to in ggplot

房东的猫 提交于 2019-12-24 00:14:57

问题


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) 

回答1:


How about this:

ggplot(mtcars, aes(mpg, disp))+
    geom_point()+
    annotate("text",25,400, label=("'Large fish' >= 45 ~ 'cm'"), parse=TRUE, hjust=0)



回答2:


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)


来源:https://stackoverflow.com/questions/43587386/annotate-with-greater-than-or-equal-to-in-ggplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!