How to annotate() ggplot with latex

前端 未结 3 629
青春惊慌失措
青春惊慌失措 2020-12-13 09:19

I\'d like to add latex text to a ggplot2 plot using annotate(). Using expression(), as described here for adding latex to axis labels, does not see

3条回答
  •  离开以前
    2020-12-13 09:39

    There is an R package called latex2exp which may be helpful. It has function TeX which accepts some LaTeX expressions enclosed with dollar sign $ as in this example:

    library(latex2exp)
    library(ggplot2)
    
    qplot(1, "A")+
         ylab(TeX("Formula: $\\frac{2hc^2}{\\lambda^\\beta}$"))+
         xlab(TeX("$\\alpha$"))
    

    More examples can be found in this vignette.

提交回复
热议问题