tidyverse / ggplot2

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

Default labs where geom when the aesthetic is in both the ggplot and geom_* call #5894

Open davidhodge931 opened 1 month ago

davidhodge931 commented 1 month ago

Default labs are not created based on aesthetics in the geom when the aesthetic is in both the ggplot and geom_* call

library(tidyverse)
library(palmerpenguins)

penguins |> 
  ggplot(aes(x = flipper_length_mm, y = body_mass_g, colour = sex)) +
  geom_point(aes(x = bill_depth_mm, y = bill_length_mm, colour = species))
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_point()`).

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

teunbrand commented 1 month ago

Should be fixed in the label refactoring in #5879. OTOH, some people might expect the global aesthetics to overrule local aesthetics.

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

palmerpenguins::penguins |> 
  ggplot(aes(x = flipper_length_mm, y = body_mass_g, colour = sex)) +
  geom_point(aes(x = bill_depth_mm, y = bill_length_mm, colour = species))
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_point()`).

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