Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: parse expressions for geom_dl() #46

Open
eggrandio opened this issue Mar 4, 2022 · 2 comments
Open

Request: parse expressions for geom_dl() #46

eggrandio opened this issue Mar 4, 2022 · 2 comments

Comments

@eggrandio
Copy link

eggrandio commented Mar 4, 2022

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.

@tdhock
Copy link
Owner

tdhock commented Jul 21, 2022

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.

@tdhock
Copy link
Owner

tdhock commented Jul 21, 2022

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
directlabels-math

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants