tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.48k stars 2.02k forks source link

`after_*()` length checks #5902

Closed teunbrand closed 4 months ago

teunbrand commented 4 months ago

This PR aims to fix #5901.

Briefly, when after_stat() or after_scale() produce aesthetics of the wrong length, a warning is thrown that the function could not be applied.

The reprex from the issue now renders with a warning:

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

ggplot(mpg[15:16, ], aes(displ, hwy)) +
  geom_point(
    aes(colour = after_scale(c("red", "green", "blue")))
  )
#> Warning: Failed to apply `after_scale()` for the following aesthetic: colour.

Created on 2024-05-22 with reprex v2.1.0

I have an alternate agenda with this PR. Moving this check into Geom$use_defaults() frees us from having to do so in the legend code, allowing a simplification I ultimately need for #5833.

teunbrand commented 4 months ago

Thanks for the review Thomas!