directlabels
directlabels copied to clipboard
Request: parse expressions for geom_dl()
Hi,
I was wondering if there is a way of parsing expressions to use as direct labels. For example, to use superscript, having test1^test2
as label would be plotted as test1test2. ggplot2
geom_text
has a parse option that if set to TRUE will parse expressions.
For example, ggrepel
has the parse
flag to use expressions, but you have to "hide" the unwanted labels and leave only one per group to be able to do the same as with a directlabel. If I have to do this for different plots, with different groups, it is almost impossible to always select the point with the most optimal label placement.
See also this question in stackoverflow.
Hi @eggrandio that sounds like a useful feature, that is currently not supported by directlabels. If you would like to implement it, I would consider a PR.
a work-around which I use to achieve the same effect (math in direct labels) is using tikzDevice, for example
gg <- ggplot()+
...
directlabels::geom_dl(aes(
change, cost_candidates,
color=Algorithm,
label.group=Algorithm,
label=sprintf("$\\tau^*_{%d} = %d$", up.to.t, tau)),
method="bottom.polygons",
debug=TRUE,
data=COST(cost.dt))
tikzDevice::tikz("tikz-graphics.tex", width=5.4, height=2.5)
print(gg)
dev.off()
taken from https://github.com/tdhock/LOPART-paper/blob/master/figure-candidates.R makes
these slides https://github.com/tdhock/LOPART-paper/raw/master/slides.pdf with images like this