I have below ggplot :
library(ggplot2)
library(ggtext)
library(ggdist)
library(latex2exp)
set.seed(123)
DF <- rbind(data.frame('Label' = 'A', val = rnorm(200, 5)),
data.frame('Label' = 'B', val = rnorm(500, 10)))
ggplot(DF, aes(Label, val)) +
stat_dots(aes(fill = Label)) +
geom_textbox(aes(-Inf, -Inf, hjust = 0, vjust = 0, label = parse(text = TeX(r'(\tau)'))), data.frame())
Basically I want to write LaTeX syntax inside a textbox in ggplot window. Here I have given a small example, however in my original case I have a big LaTeX expression.
With above code, I am getting below error :
Don't know how to automatically pick scale for object of type expression. Defaulting to continuous.
Error: Aesthetics must be valid data columns. Problematic aesthetic(s): label = parse(text = TeX("\\tau")).
Did you mistype the name of a data column or forget to add after_stat()?
Any pointer how to use LaTeX within a textbox in ggplot will be very helpful.
Thanks for your pointer.


?latex2exp::latex2exp_supported()doesn't seem to includetauand can thus not translate it toplotmath. A workaround is constructing your own expression liketxt <- as.expression(paste0(sprintf('%s', "\u03C4"), " / 5"))andeval(txt)it to form the label, but that's not latex-like. Alternatively, can add these features by carefully looking at github.com/stefano-meschiari/latex2exp/blob/main/R/latex2exp.R, the implementation behind the TeX function.