Skip to content

I() is not working with discrete scales #6563

@jospueyo

Description

@jospueyo

I found a problem with using I() with discrete scale and annotate. The text is placed according to the position in the scale and not to the position in the plot. The same plot works as expected with a continuous scale.

Here is the code to reproduce the bug:

library(ggplot2)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

tibble(
  x = sample(0:10, 100, replace = T),
  y = sample(letters[1:10], 100, replace = T),
) |> 
  ggplot(aes(x = x, y = y)) +
  geom_point() +
  geom_text(
    x = I(0.5),
    y = I(0.5),
    label = "A",
    color = "red"
  )

  tibble(
    x = sample(0:10, 100, replace = T),
    y = sample(0:10, 100, replace = T)
  ) |> 
  ggplot(aes(x = x, y = y)) +
    geom_point() +
    geom_text(
      x = I(0.5),
      y = I(0.5),
      label = "A",
      color = "red"
    )

Created on 2025-07-28 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