-
-
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
Support for hjust and vjust #3
Comments
Thanks for the suggestion! I have been thinking about removing the May I ask you to share a minimal example where you think these parameters might be useful? For example: library(ggplot2)
library(ggrepel)
ggplot(...) + geom_line(...) + geom_text_repel(...) If we can't find any compelling examples to support the use of these parameters, then I'll go ahead and remove them. I agree that the documentation needs to be improved, and that's on my todo list. By the way, pull requests are very welcome! I'd be happy to review and merge changes if you wish to fork this repo. |
So if I used hjust/vjust, I might be able to indicate my preference for the labels to not overlap the line, subject to the constraints of the force-directed layout.
What actually happens in this case is that
I'm guessing that (1) is due to lack of support for hjust/vjust in the segment computation, and (2) is due to some compromise between the force-directed layout and hjust/vjust. I can think of a couple of ways to resolve this:
I still haven't had a chance to do much digging into the code, and probably won't until Friday at the earliest, but I hope this at least makes it clearer. |
Thank you for the detailed examples and suggestions! I decided to drop support for If you're interested to continue working on this, I'd be happy to review a pull request. I think you're right about the possibility for hjust/vjust to influence the algorithm. It'd be cool to see what you come up with. You might consider an alternative approach to labeling lines directly by using the directlabels package for this particular use case. Alternatively, you might also consider increasing the |
@srvanderplas, could I ask if you have any thoughts about the new (not yet implemented) feature proposed in issue #11? I'm wondering what you think about this idea. Do you think this feature is preferable to something more like I think the new feature might address the issue you raised. We can start with the plot you mentioned above: p <- ggplot(data = data, aes(x = x, y = y, color = group)) +
geom_line() +
geom_point() First, we could use p +
coord_cartesian(xlim = c(1, 5.5)) +
geom_label_repel(data = subset(data, x == 5), aes(label = group)) Next, we could pass a directions <- data.frame(
up = rep(1, 5), right = rep(1, 5), down = rep(1, 5), left = rep(0, 5))
# up right down left
# 1 1 1 1 0
# 2 1 1 1 0
# 3 1 1 1 0
# 4 1 1 1 0
# 5 1 1 1 0
p +
coord_cartesian(xlim = c(1, 5.5))
geom_label_repel(
data = subset(data, x == 5),
aes(label = group),
directions = directions
) What do you think? |
Hi Susan, could I ask you to try the new devtools::install_github("slowkow/ggrepel@0.4.2")
library(ggrepel)
set.seed(42)
groups <- c("AAAAAAA", "BBBBB", "CCCCCCC", "DDDDDDD", "EEEE")
data <- data.frame(x = rep(1:5, times = 5), y = rnorm(25, 0, 1),
group = rep(groups, each = 5))
ggplot(data = data, aes(x = x, y = y, color = group)) +
geom_line() +
geom_point() +
coord_cartesian(xlim = c(min(data$x), max(data$x) + 0.5)) +
geom_label_repel(
data = subset(data, x == 5),
aes(label = group),
segment.color = NA,
size = 5,
nudge_x = 0.25
) |
Feel free to reopen this issue if you want to continue this discussion! |
Currently, using
hjust
andvjust
ggplot2 parameters will cause the labels not to line up with the segments connecting them to points. It's arguable that using ggrepel should remove the need for these parameters, but in some use cases (labeling lines, for instance, and trying to reduce overlap with the line) it may be desirable to use one or both of these parameters in addition to ggrepel.Alternately, expand the documentation for ggrepel so that it is clear that these parameters aren't supported.
The text was updated successfully, but these errors were encountered: