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

draw_key_rect fails to get color from outline when fill is NA #5385

Open
Ductmonkey opened this issue Aug 10, 2023 · 5 comments
Open

draw_key_rect fails to get color from outline when fill is NA #5385

Ductmonkey opened this issue Aug 10, 2023 · 5 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@Ductmonkey
Copy link

Ductmonkey commented Aug 10, 2023

Problem:

When using draw_key_rect with a geom that has fill = NA, it fails to catch the outline color and returns an invisible (NA) rectangle.

Minimal reprex:

library(ggplot2)
ggplot(mtcars, aes(disp, color = factor(cyl))) + geom_density(key_glyph = draw_key_rect)

Created on 2023-08-10 with reprex v2.0.2

@Ductmonkey Ductmonkey changed the title Improved documentation of draw_key_* [documentation] Improved documentation of draw_key_* Aug 10, 2023
@clauswilke
Copy link
Member

I think this is actually a bug. The rectangle draw key was meant to pick up the outline color when the fill color isn't given, but that apparently doesn't work. Not sure if it did work in the past and doesn't anymore or if it never worked.

The problem is in this line:

fill = alpha(data$fill %||% data$colour %||% "grey20", data$alpha),

It is meant to pick colour when fill is not given, but here fill is set to NA and %||% tests for NULL.

There's nothing to change in the documentation, because the data, params, and size arguments to the draw key functions are not meant to be used by the end-user.

@Ductmonkey
Copy link
Author

Thanks for clarifying, very helpful! Can you migrate this to a bug report then?

@clauswilke clauswilke added the bug an unexpected problem or unintended behavior label Aug 10, 2023
@clauswilke
Copy link
Member

You can just edit the title accordingly. I've added the "bug" label.

@Ductmonkey Ductmonkey changed the title [documentation] Improved documentation of draw_key_* draw_key_rect fails to get color from outline when fill is NA Aug 10, 2023
@Ductmonkey
Copy link
Author

Not realizing it was a bug, I had also asked this as a question on StackOverflow. Stefan's answer there may help on this:
https://stackoverflow.com/q/76872072/13210554

@Ductmonkey Ductmonkey changed the title draw_key_rect fails to get color from outline when fill is NA draw_key_rect fails to get color from outline when fill is NA Aug 10, 2023
@teunbrand
Copy link
Collaborator

I agree that this is a bug, but there currently isn't a way of distinguishing whether the fill = NA comes from the defaults, in which case the colour should override, or it comes the user, in which case it shouldn't.

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
Projects
None yet
Development

No branches or pull requests

3 participants