Skip to content

annotate with geoms "hline" and "vline" does not add a line #2011

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
aphalo opened this issue Jan 21, 2017 · 1 comment
Closed

annotate with geoms "hline" and "vline" does not add a line #2011

aphalo opened this issue Jan 21, 2017 · 1 comment

Comments

@aphalo
Copy link
Contributor

aphalo commented Jan 21, 2017

I demonstrate the problem here only for geom_hline, but the same problem affects geom_vline.

ggplot(data.frame(x = 0:5, y = 0:5), aes(x, y)) +
     geom_point() +
     annotate(geom = "hline",
                     yintercept = 2.5)

rplot

Adding an y argument produces the expected output, with a warning:
Warning: Ignoring unknown aesthetics: y

ggplot(data.frame(x = 0:5, y = 0:5), aes(x, y)) +
    geom_point() +
    annotate(geom = "hline",
                    yintercept = 2.5, y = 2.5)

rplot01

There is something odd going on: when y is present, the hline is plotted at the yintercept position, but the "ignored" unknown aesthetics still affects the scale limits.

ggplot(data.frame(x = 0:5, y = 0:5), aes(x, y)) +
     geom_point() +
     annotate(geom = "hline",
                     yintercept = 2.5, y = 100)

rplot02

ggplot2 2.2.1.9000 installed minutes ago.

Hope this helps diagnose the problem.

@hadley
Copy link
Member

hadley commented Jan 23, 2017

Yes, unfortunately vline and hline are weird geoms that "self" annotate - just do geom_hline(yintercept = 2.5)

@hadley hadley closed this as completed Jan 23, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants