Skip to content

Cannot pass check.aes through geom_* to layer #1869

Closed
@wmurphyrd

Description

@wmurphyrd

My colorplaner ggplot2 extension involves a scale which accepts an aesthetic unknown to the layer and maps that aesthetic to one the layer accepts (specifically, a secondary color/fill mapping translated through a bivariate color scale to color or fill).

With the changes in befc4d0 for issue #1585, a warning is now generated if that mapping is created at the layer level:

library(ggplot2)
library(colorplaner)
ggplot(mtcars, aes(x = drat, y = mpg)) +
  geom_point(aes(color = hp, color2 = disp)) +
  scale_color_colorplane()
Warning: Ignoring unknown aesthetics: color2

In this instance the warning is untrue, as the scale interprets color2 and the plot is generated as expected. However, since the layers are ignorant of their scales, I cannot figure out a solution to inform the layers of the scale's handling of the aesthetic to avoid this warning. This isn't a show stopper as the mapping can simply be done at the plot level or the warning can be ignored, but it could certainly introduce confusion to users.

The layer function now includes a check.aes parameter option to skip this checking, but it does not seem possible to pass that parameter through the standard geom_* constructors, as the ... arguments to geom_* get wrapped up in a params list passed on to layer (e.g. in geom_point here).

ggplot(mtcars, aes(x = drat, y = mpg)) +
  geom_point(aes(color = hp, unknown_aes = disp), check.aes = FALSE)
Warning: Ignoring unknown parameters: check.aes
Warning: Ignoring unknown aesthetics: unknown_aes

Would you consider a PR that altered layer() to look for and honor check.aes and check.param within its params argument?

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