Skip to content
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

The I function does not work as expected on categorical y axis and numeric x axis #6308

Open
davidhodge931 opened this issue Jan 27, 2025 · 2 comments · May be fixed by #6311
Open

The I function does not work as expected on categorical y axis and numeric x axis #6308

davidhodge931 opened this issue Jan 27, 2025 · 2 comments · May be fixed by #6311
Labels
bug an unexpected problem or unintended behavior

Comments

@davidhodge931
Copy link

davidhodge931 commented Jan 27, 2025

Note behaviour of the annotated label in p2 below. I would have expected it to match that in p1

library(tidyverse)
library(palmerpenguins)
library(patchwork)

p1 <- penguins |>
  ggplot() +
  geom_point(
    aes(x = flipper_length_mm, 
        y = body_mass_g),
  ) +
  annotate("label", x = I(0.2), y = I(0.8), label = "Here")

p2 <- penguins |> 
  ggplot() +
  geom_bar(
    aes(y = sex, fill = species), position = "dodge",
  ) +
  annotate("label", x = I(0.2), y = I(0.8), label = "Here") 

p1 + p2
Image
@davidhodge931 davidhodge931 changed the title The identity function does not work as expected on categorical y axis and numeric x axis The I function does not work as expected on categorical y axis and numeric x axis Jan 27, 2025
@teunbrand
Copy link
Collaborator

Thanks for the report! I agree this is a bug

@teunbrand teunbrand added the bug an unexpected problem or unintended behavior label Jan 29, 2025
@teunbrand
Copy link
Collaborator

teunbrand commented Jan 29, 2025

Simplified reprex, the label should be in the right part of the plot:

library(ggplot2)

ggplot(mpg, aes(drv, displ)) +
  geom_boxplot() +
  annotate("label", label = "foobar", x = I(0.75), y = 2)

Created on 2025-01-29 with reprex v2.1.1

The issue is caused by this here code:

rescale(self$map(x, limits = limits), from = range)

Where the scale maps AsIs variables to the <mapped_discrete> class, thereby skipping the rescale.AsIs method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants