This question is related to an issue raised in the ggrepel GitHub repo:
https://github.com/slowkow/ggrepel/issues/153
Suppose the following series of events:
- A user creates a plot, and adds a layer with geom_text_repel()
- Then, adds a second layer with another call to geom_text_repel()
Problem
Currently, the second layer cannot "see" the first layer. So, the two layers are completely independent of each other. So, the text labels end up overplotted on top of each other. This is not the behavior that users are expecting. Users expect the text labels to be aware of each other, and avoid the previously plotted labels.
Possible solution?
What if the second layer could "see" the first layer, somehow? Is this technically feasible?
In the GitHub issue, I propose a half-baked idea:
- Add a side-effect to the call to geom_text_repel(), so that it write x,y coordinates to a temporary file. Then, subsequent calls would look for coordinates in that file and repel text labels from those coordinates.
I'm not happy with temporary files, because they might accumulate and use a lot of disk space.
Is there any other way? Could we perhaps implement a different sort of side-effect like adding specially-named columns to the underlying dataframe? E.g., add columns called "_ggrepel_1_x" and "_ggrepel_1_y" for the first call, and then "_ggrepel_2_x" "_ggrepel_2_y" for the second call, etc.
What do you think?
Can you think of any other use-cases for a "cascading" effect where each layer in a ggplot is saved somewhere, so subsequent layers can "see" previous layers?
Thanks for your thoughts,
Kamil