Skip to content

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

Closed
@aphalo

Description

@aphalo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions