Skip to content

annotate() with hline and vline geoms #4719

Closed
@mikkmart

Description

@mikkmart

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions