Skip to content

geom_raster drops legend when col and fill aesthetics added #5324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
davidhodge931 opened this issue Jun 14, 2023 · 2 comments · Fixed by #5328
Closed

geom_raster drops legend when col and fill aesthetics added #5324

davidhodge931 opened this issue Jun 14, 2023 · 2 comments · Fixed by #5328
Labels
bug an unexpected problem or unintended behavior guides 📏

Comments

@davidhodge931
Copy link

davidhodge931 commented Jun 14, 2023

legend works with geom_tile when col then fill aesthetics added

library(tidyverse)

#legend works with geom_tile
ggplot2::faithfuld |>
  head(10) |> 
  ggplot() +
  geom_tile(aes(x = waiting, y = eruptions, col = density, fill = density)) 

legend does not work with geom_raster when col then fill aesthetics added

#legend does not work with geom_raster
ggplot2::faithfuld |>
  head(10) |> 
  ggplot() +
  geom_raster(aes(x = waiting, y = eruptions, col = density, fill = density))
#> Warning in geom_raster(aes(x = waiting, y = eruptions, col = density, fill =
#> density)): Ignoring unknown aesthetics: colour

Created on 2023-06-15 with reprex v2.0.2

@davidhodge931
Copy link
Author

Works if the order of aesthetics is fill then col, but not the other way around

library(tidyverse)

#legend works if aesthetic order is fill then col
ggplot2::faithfuld |>
  head(10) |>
  ggplot() +
  geom_raster(aes(x = waiting, y = eruptions, fill = density, col = density))
#> Warning in geom_raster(aes(x = waiting, y = eruptions, fill = density, col =
#> density)): Ignoring unknown aesthetics: colour

Created on 2023-06-15 with reprex v2.0.2

@teunbrand
Copy link
Collaborator

teunbrand commented Jun 17, 2023

Good catch! From some brief experimentation, it seems to be dropped due to the legend key data having colour as the aesthetics name after merging fill and colour guides, which then is discarded by the guide_geom()/GuideColourbar$get_layer_key(). I think this should be fixed in the guide_merge()/GuideColourbar$merge() step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior guides 📏
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants