Skip to content

Order of <AsIs> may disrupt scales. #5596

Closed

Description

@teunbrand

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

Activity

  1. teunbrand commented on Dec 18, 2023

    @teunbrand
    CollaboratorAuthor

    Considered fixed by #5597

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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