Skip to content

geom_raster drops legend when col and fill aesthetics added #5324

Closed

Description

@davidhodge931

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

Activity

  1. davidhodge931 commented on Jun 14, 2023

    @davidhodge931
    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

  2. teunbrand commented on Jun 17, 2023

    @teunbrand
    Collaborator

    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.

  3. added
    bug
    on Jun 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugguides 📏

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions