slowkow / ggrepel

:round_pushpin: Repel overlapping text labels away from each other in your ggplot2 figures.
https://ggrepel.slowkow.com
GNU General Public License v3.0
1.22k stars 96 forks source link

Use of repel algorithm in other packages? #202

Open aravind-j opened 3 years ago

aravind-j commented 3 years ago

I am developing a ggplot2 extension (gglyph) and would like to use the repel algorithm from ggrepel. I am able to get desired results even though I am trying to repel polygon grobs instead of text grobs.

image

image

Are you still considering exporting ggrepel:::repel_boxes2() ? or can I copy the necessary code in my package with attribution as in the case of metacoder and as discussed in #88 ?

slowkow commented 3 years ago

Thanks for the question! Your package looks interesting, and I'm impressed that you're successfully using the repel_boxes2() function. Your example helps me to understand why this function might be useful for other developers.

The license gives permission for any developer to copy code from ggrepel. There's no need to ask me for permission.

Feel free to decide for yourself whether you'd like to copy the code and modify it, or if you'd like to add ggrepel as a dependency.

If you want to avoid waiting for me, then the fastest way forward is to copy the code. This approach also gives you ultimate freedom to customize absolutely everything exactly as you want for your particular application.

If you prefer to add ggrepel as a dependency, then this might take some time. I would need to upload a new release of ggrepel on CRAN where the repel_boxes2() function is exported. I don't want to cause any delays for you, but I don't know if I can upload a new release to CRAN any time soon. Updates for ggrepel can take some time, because I want to be sure that I'm not breaking anything or introducing new bugs. It can be very time-consuming to try to make changes safely.

If you think that exporting repel_boxes2() is a good idea, then you might consider helping with ggrepel development by creating a pull request with these changes:

m-jahn commented 2 years ago

Just a follow-up on this: I am also interested in having repel_boxes2 exported in ggrepel, so that other functions/packages can use it. Specifically, I'm using a lot of lattice plots but there is no function that works as well as ggrepel in repelling labels.

What I did now was to copy the C++ function and add it to my own package latticetools, from where it is exported. That means in this package, repel_boxes can be called directly. But the main usage is to call it from within a lattice panel function, panel.repellabels (the counter part of a ggplot geom). I have added you @slowkow as a co-author for the package, and in the long run might give your suggestion a try to export it directly in ggrepel, as you mentioned above.

slowkow commented 2 years ago

@m-jahn Thank you for the kind note! I think copying the code is a fine solution, and gives you freedom to change everything. 👍

m-jahn commented 2 years ago

Great! That said, are you @slowkow as the ggrepel maintainer still interested in having repel_boxes(2) exported according to your suggestion in your previous comment? Since I did it now for my own package, it would be easy to make a commit + PR for ggrepel too, and that would settle these and future requests for a standalone box repel function.

slowkow commented 2 years ago

@m-jahn I would be very happy to merge a PR that exports a usable function, but I don't have time right now to write the PR by myself or to test it extensively.

If you decide to do this, please do add yourself as an author to the DESCRIPTION file, and add a new item in the NEWS.md file to summarize the change.

I think the ideal PR might also include a new documentation page that shows code examples for how developers might use the exported function.

m-jahn commented 2 years ago

Thanks @slowkow, I think I will give it a try.

pstraforelli commented 2 years ago

As an FYI, there is this package that may be of interest to you @m-jahn and @aravind-j https://github.com/hms-dbmi/repel