Skip to content

annotate() with hline and vline geoms #4719

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

Closed
mikkmart opened this issue Jan 27, 2022 · 4 comments · Fixed by #4721
Closed

annotate() with hline and vline geoms #4719

mikkmart opened this issue Jan 27, 2022 · 4 comments · Fixed by #4721
Labels
feature a feature request or enhancement layers 📈

Comments

@mikkmart
Copy link

I was adding other annotations to a plot, and wanted to add reference lines. I was in the mindset of annotate()ing thigs, so I tried to use it with "hline" and "vline", but discovered that nothing happened. For example:

library(ggplot2)

p <- ggplot(data.frame(x = 1, y = 1), aes(x, y)) + geom_point()

p +
  annotate("hline", yintercept = 0) +
  annotate("vline", xintercept = 0)

What I expected:

p +
  annotate("segment", x = -Inf, xend = Inf, y = 0, yend = 0) +
  annotate("segment", x = 0, xend = 0, y = -Inf, yend = Inf)

I realize the “solution” here is to use the geoms directly with fixed values:

p +
  geom_hline(yintercept = 0) +
  geom_vline(xintercept = 0)

But annotate() not working seems like an unexpected inconsistency.

@smouksassi
Copy link

dup of #1052

@mikkmart
Copy link
Author

Thanks @smouksassi, I didn't think to look that far back. If this is indeed expected behaviour, perhaps a documentation patch would be in order? I could prepare something.

@mikkmart
Copy link
Author

And/or, indeed, a warning if "abline", "hline" or "vline" are passed to annotate() as the geom, with instructions to use the corresponding geom directly.

@mikkmart
Copy link
Author

(Also a duplicate of #2011. I should definitely have included "hline" in my initial search, rather than just "annotate".)

@hadley hadley added feature a feature request or enhancement layers 📈 labels Mar 14, 2022
hadley pushed a commit that referenced this issue Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement layers 📈
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants