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

Cannot override.aes with guide_bins? #4085

Closed
jdsher opened this issue Jun 23, 2020 · 1 comment · Fixed by #4104
Closed

Cannot override.aes with guide_bins? #4085

jdsher opened this issue Jun 23, 2020 · 1 comment · Fixed by #4104
Labels
bug an unexpected problem or unintended behavior guides 📏
Milestone

Comments

@jdsher
Copy link

jdsher commented Jun 23, 2020

Controlling the appearance of the geoms within a scale_size_binned legend using guide_bins() doesn't seem to operate in the same fashion as guide_legend() - or rather, there appears to be no overriding the aes() despite the documentation implying no difference.

To illustrate, this:

ggplot(mtcars, aes(x = drat, y = wt, size = hp, fill = cyl)) + 
geom_point(shape = 21) + 
scale_size_binned(guide = guide_legend(override.aes = list(colour = "red", shape = 21, fill = "blue")))

...works as expected, while this:

ggplot(mtcars, aes(x = drat, y = wt, size = hp, fill = cyl)) + 
geom_point(shape = 21) + 
scale_size_binned(guide = guide_bins(override.aes = list(colour = "red", shape = 21, fill = "blue")))

...does not.

@yutannihilation
Copy link
Member

Thanks, confirmed. It seems we just forget to pass override.aes to the guide...

ggplot2/R/guide-bins.R

Lines 92 to 129 in cb0cfd2

structure(list(
# title
title = title,
title.position = title.position,
title.theme = title.theme,
title.hjust = title.hjust,
title.vjust = title.vjust,
# label
label = label,
label.position = label.position,
label.theme = label.theme,
label.hjust = label.hjust,
label.vjust = label.vjust,
# key
keywidth = keywidth,
keyheight = keyheight,
# ticks
axis = axis,
axis.colour = axis.colour,
axis.linewidth = axis.linewidth,
axis.arrow = axis.arrow,
# general
direction = direction,
default.unit = default.unit,
reverse = reverse,
order = order,
show.limits = show.limits,
# parameter
available_aes = c("any"),
...,
name = "bins"),
class = c("guide", "bins")
)

Rendered reprex:

library(ggplot2)
library(patchwork)

ggplot(mtcars, aes(x = drat, y = wt, size = hp, fill = cyl)) + 
  geom_point(shape = 21) + 
  scale_size_binned(guide = guide_legend(override.aes = list(colour = "red", shape = 21, fill = "blue")))

ggplot(mtcars, aes(x = drat, y = wt, size = hp, fill = cyl)) + 
  geom_point(shape = 21) + 
  scale_size_binned(guide = guide_bins(override.aes = list(colour = "red", shape = 21, fill = "blue")))

Created on 2020-06-30 by the reprex package (v0.3.0)

@thomasp85 thomasp85 added bug an unexpected problem or unintended behavior guides 📏 labels Aug 31, 2020
@thomasp85 thomasp85 added this to the ggplot2 3.3.4 milestone Mar 25, 2021
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.

3 participants