Skip to content

Identity function does not position annotations where expected when x = 0 #6493

Closed
@davidhodge931

Description

@davidhodge931

Identity function does not position annotations where expected when x = 0. It does when x = -Inf

Not sure if this is a ggplot thing?

library(tidyverse)
library(palmerpenguins)
#> 
#> Attaching package: 'palmerpenguins'
#> The following objects are masked from 'package:datasets':
#> 
#>     penguins, penguins_raw

p <- penguins |>
  ggplot() +
  geom_bar(aes(x = species), ) +
  theme_classic()

p +
  ggplot2::annotate(
    "segment",
    x = I(0),
    xend = I(1),
    y = c(50, 100),
    yend = c(50, 100),
    colour = "red"
  ) +
  coord_cartesian(clip = "off")

p +
  ggplot2::annotate(
    "segment",
    x = I(-Inf),
    xend = I(1),
    y = c(50, 100),
    yend = c(50, 100),
    colour = "red"
  ) +
  coord_cartesian(clip = "off")

Created on 2025-06-05 with reprex v2.1.1

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