tidyverse / ggplot2

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

Scales with no matching data throw warnings #5909

Closed teunbrand closed 1 month ago

teunbrand commented 1 month ago

This PR aims to fix #3743.

Briefly, a warning is thrown when a scale was declared, but none of the data has the relevant aesthetic.

I had to touch the build method to coordinate this warning, but if extensions don't update they should skip the warning, so it should be safe.

Reprex from issue:

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

ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
  geom_boxplot() +
  scale_colour_brewer(
    name = 'Dude which plant',
    palette = 'Set2'
  )
#> Warning in scale_colour_brewer(name = "Dude which plant", palette = "Set2"):
#> Scale for colour aesthetic was provided but has no matching data to map.

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

teunbrand commented 1 month ago

I'm closing this, there are too many spurious cases where this warning is thrown