-
-
Notifications
You must be signed in to change notification settings - Fork 96
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
How to get the coordinates (x, xend, y, yend) of an annotate(text) #155
Comments
I'm not sure if I understand what you are looking for. Is your issue the same as #35? You might consider sharing a code snippet, a figure showing the output, and a description of your goals or issues. |
Difficult to add a code, as it request to have external shape files and I don't want to copy/paste something I'm developing. The issue is simple in the ggrepel() function, what in the code made that the segment is automaticaly adjusted depending on the label size? |
Well I wrote quickly the code below :
The point is that for "Point 1" text overlaps the segment that relates to the point. Is there a way to automaticaly adjust the segment to the text? In other words is there a way to get the coordinates of a the 4 points (x, xend, y, yend) of the virtual box that circle the text "Point 1" in order to determine the coordinates for my annotate("segment",...)? |
You might consider reading the source code. |
Dear slowkow, Thanks for your answer. That's exactly what I want to do, but I'm still an "amateur" and don't know how to deal with this. Is there a way to be shunt? In a previous exchange by e-mail, you point an interesting track:
Where is it possible to have access to this internal code? Indeed estimating the size of the text label is exactly what I want to get in order to accurately estimate to xend parameter of my annotate("segment", …) function. |
You might want to look at https://stat.ethz.ch/R-manual/R-devel/library/grid/html/xDetails.html Here is the code in ggrepel: Lines 369 to 372 in e2943a1
I must admit that the code in ggrepel is not ideal, but it seems to work well enough. I think that a grid expert would write the code differently. Feel free to play around and discover what works for you. |
Dear slowkow, Thanks a lot for your super help, I think that it is definitely the track I was looking for! I'll play with this part of your code. I'll be back asap with news and hopefully to close the discussion! Regarding the code of ggrepel, I'm surely not an expert, but look to all the people that use ggrepel(), most of them don't look at the core of the code (fortunatelly), they use it as a tools and it's definitely a cool & useful tool :-)! |
I worked on the track, and I'm facing a new issue. Even if I used the "native" parameter for unit in the convert() functions I have a difference of unit between my initial ggplot and the coordinates obtained with convertWidth() and convertHeight(). Here is the code:
Here is the summary of the output:
The positive point is that the font size of info_1, that is supposed to be 10 times bigger than the one of info_2, has a wider text box (114,99 > 11.999 (~ factor 10) ). The negative point is the difference of unit between coordinates of map and info_1/info_2. Do anybody has a clue? |
Summary
Hello everyone,
My question is not directly related to an issue with ggrepel(). But actually ggrepel address perfectly the problem I'd like to solve.
I'm working on a similar (but not so developped) function to the one of ggrepel. I'd like to avoid that an annotate("segment",...) overlaps an annotate("text",...).
Part of the code is avaible here:
In order to overcome this issue, I had in mind to get the coordinates of the virtual box around my text zone (like x, xend, y, and yend) in order to determine this coordinates in my annotate("segment",...).
The point as you can see on my code above is that I only entered x & y value in my annotate("text",...).
Actually I'm looking for something similar to the following code I found in order to get the extrem coordinates of the plot area of a ggplot object with the following code :
To your knowledge is there a similar code to get coordinates of a annotate("text",...) box ?
I hope that my question is clear enough for somebody to help me... Feel free to ask for more elaborate description
Version information
Here is the output from
sessionInfo()
in my R session:The text was updated successfully, but these errors were encountered: