Skip to content

after_scale fails to find some aesthetic variables #3725

Closed
@atusy

Description

@atusy

I am highlighting some points by a combination of stage() and after_scale().
I found that after_scale can find aesthetic variables, but not variables in the original data.
It is fine, if that's a design.
As a workaround, I let after_scale find the variable in the data by mapping it to an aesthetic variable.
It works in some case, but not always.
As far as I tried, it seems the error is related to discrete variables.

library(ggplot2)
g <- ggplot(mtcars) +
    aes(wt, mpg, highlight = am == 1) +
    geom_point(
        aes(colour = stage(cyl, after_scale = ifelse(highlight, colour, 'gray'))),
        shape = 21
    )

# Okay
g

# Okay
g + aes(fill = am)

# Error
g + aes(fill = as.factor(am))
#> Error in ifelse(highlight, colour, "gray"): object 'highlight' not found

# Error
ggplot(iris) +
    aes(Sepal.Length, Sepal.Width, highlight = Species == "setosa") +
    geom_point(
        aes(
            colour = stage(
                Species, after_scale = ifelse(highlight, colour, 'gray')
            )
        )
    )
#> Error in ifelse(highlight, colour, "gray"): object 'highlight' not found

Created on 2020-01-13 by the reprex package (v0.3.0.9001)

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