Skip to content
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

Adding override.aes() to guide_colorbar() #5085

Closed
ajjitn opened this issue Dec 5, 2022 · 2 comments · Fixed by #5550
Closed

Adding override.aes() to guide_colorbar() #5085

ajjitn opened this issue Dec 5, 2022 · 2 comments · Fixed by #5550
Labels
feature a feature request or enhancement guides 📏

Comments

@ajjitn
Copy link

ajjitn commented Dec 5, 2022

It seems like guide_colorbar() doesn't support override.aes() like its other guide_*() counterparts. As an example:

library(tidyverse)
mtcars %>% 
  ggplot(aes(x = mpg, y = disp)) +
  geom_point(aes(color=disp), alpha = 0.5) +
  # Below line has no effect because guide_colorbar doesn't support override.aes
  guides(color = guide_colorbar(override.aes = list(alpha = 0.5)))

# Using guide_legend works, but converts to incorrect binned legend instead of colorbar legend
mtcars %>% 
  ggplot(aes(x = mpg, y = disp)) +
  geom_point(aes(color=disp), alpha = 1) +
  guides(color = guide_legend(override.aes = list(alpha = 0.5)))

I would like to adjust the colorbar legend to also have alpha = 0.5 for consistency but I can't seem to find a good way to do this without using override.aes(). I think having override.aes() available in guide_colorbar would be useful in situations like this to maintain consistency across the plot.

As another example use case, I often make choropleth maps with continuous colorbar legends using geom_sf and often fiddle with the alpha transparency of some layers to make the maps more readable . It would be nice to have the colorbar legend reflect these changes. Totally understand if this is very complex, but just thought I'd ask!

@teunbrand
Copy link
Collaborator

I think the reason that the colourbar/coloursteps guides don't have an override.aes argument is because it doesn't take any information from the layers, aside from whether there is an appropriate layer (as opposed to legend, which copies details from aesthetics). I don't really see an alpha as a mapping that can be reflected in a colourbar, but it would makes sense as a fixed property. Aside from alpha, are there any aesthetics that are eligible to be overridden in colourbars?

@teunbrand teunbrand added feature a feature request or enhancement guides 📏 labels Dec 24, 2022
@teunbrand
Copy link
Collaborator

Anyhow, for now, if you'd need it, you could fix this at the scale/palette side of things by providing transparent colours.

library(ggplot2)

ggplot(mtcars, aes(x = mpg, y = disp)) +
  geom_point(aes(color=disp), alpha = 0.5) +
  scale_colour_gradient(
    low  = alpha("#132B43", 0.5), 
    high = alpha("#56B1F7", 0.5)
  )

Created on 2023-01-26 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement guides 📏
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants