-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
Bad repelled-location of labels #92
Comments
Always a pleasure to get an issue report from you, Pedro 😄 I agree that this is a bug, and it is probably caused by the new code that tries to resolve line segment overlaps. Thanks for the minimal example. This will be crucial to test if new code fixes the bug. If you have any ideas or want to give it a try yourself, please feel free! I'd be happy to add anyone as a contributor. Unfortunately, I must delay fixing this issue for now, so I recommend that you continue using the CRAN version that does not support Thanks again! You saved me from pushing a buggy version to CRAN 👍 |
No problem. I will be busy in the next few days so I won't be able to give it a try soon. I do not really need the new features, but I use ggrepel in the vignette of one of my own packages of which I have a new version ready to submit to CRAN. Because of this tested it with your upcoming release. If I find time to contribute to ggrepel, I think that as I am not familiar with your code, my most useful contribution would be to prepare some automated visual tests cases. I have added them to one of my packages and I am finding them very useful to detect glitches like this one. Sorry that my example is not that minimal as it uses spectral data that has more than a thousand observations! |
I reproduced the bug with another very minimal example. This is not good... gotta find a quick way to fix this. I guess the CRAN version is best for now. library(ggrepel)
set.seed(42)
# Make 100 points
dat <- data.frame(
x = rnorm(100),
y = rnorm(100),
text = sample(letters, 100, replace = TRUE),
stringsAsFactors = FALSE
)
# Label 10 points
dat_text <- dat[sample(nrow(dat), 10),]
# Let's avoid ALL data points.
dat_text2 <- dat
dat_text2$text[!rownames(dat_text2) %in% rownames(dat_text)] <- ""
ggplot() +
geom_point(
data = dat,
mapping = aes(x, y)
) +
geom_label_repel(
data = dat_text2,
mapping = aes(x, y, label = text)
)
ggsave("issue92.png", width = 4, height = 4) ggrepel 0.7.2ggrepel 0.7.0 (CRAN) |
I put in a PR to fix this problem (that was introduced by the line cross checking code -- sorry about that! Hadn't tested the scenario with only labeling a subset of points with 'label' rather than 'text'). Thanks for catching this issue @aphalo and for the minimal reprex @slowkow. I agree with @aphalo that some automated visual tests would be an awesome addition to this package! The vdiffr package might be a good approach |
@AliciaSchep @slowkow I have started adding visual tests with vdiffr. I hope to have a PR in a week or so. |
I believe Alicia's pull request #94 fixes this. |
Summary
I find that in some cases locations of labels seem to be displaced, as if some indexing is off by one. Until now, I have seen this only happening with labels bellow a line, but not above. Not with text_repel, but maybe just a question of available space.
Minimal code example
I will add a minimum example later today, but as you may be getting ready to submit the new version, this is shown as a warning of a proper example I will add by the end of the day.
This example demonstrates the issue, although it is not a minimum one.
Here is an image of the output produced by the code:
Suggestions
I have no proposal at the moment. This seems to be a bug.
Version information
Here is the output from
sessionInfo()
in my R session:The text was updated successfully, but these errors were encountered: