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

Order of <AsIs> may disrupt scales. #5596

Closed
teunbrand opened this issue Dec 18, 2023 · 1 comment · Fixed by #5597
Closed

Order of <AsIs> may disrupt scales. #5596

teunbrand opened this issue Dec 18, 2023 · 1 comment · Fixed by #5597

Comments

@teunbrand
Copy link
Collaborator

If an <AsIs> aesthetic comes after a regular aesthetic, the <AsIs> vector is not scaled.
This is good, as this was a goal of #5477.

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

df <- data.frame(
  x = 1:4, y = 1:4,
  colour = c("red", "green", "blue", "yellow"),
  group  = LETTERS[1:4]
)

ggplot(df, aes(x, y)) +
  geom_text(aes(label = group, colour = group)) +
  geom_text(aes(x = 5 - x, label = colour, colour = I(colour)))

However, if the first layer has an <AsIs> aesthetic, the second layer with a regular aesthetic has problems.
This is because scale_{aes}_identity() is still being invoked in find_scale().
This is a problem because one of the goals of #5477 was to 'unclash' such scales.

ggplot(df, aes(x, y)) +
  geom_text(aes(x = 5 - x, label = colour, colour = I(colour))) +
  geom_text(aes(label = group, colour = group))
#> Error in `geom_text()`:
#> ! Problem while converting geom to grob.
#> ℹ Error occurred in the 2nd layer.
#> Caused by error:
#> ! Unknown colour name: A

Created on 2023-12-18 with reprex v2.0.2

@teunbrand
Copy link
Collaborator Author

Considered fixed by #5597

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant