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

Error: Must request at least one colour from a hue palette when plotting NA values #5623

Closed
TimBMK opened this issue Jan 3, 2024 · 1 comment · Fixed by #5624
Closed
Labels
bug an unexpected problem or unintended behavior scales 🐍

Comments

@TimBMK
Copy link

TimBMK commented Jan 3, 2024

When using the color or fill aesthetics on a variable with only NA values, this produces the following error:
Error: Must request at least one colour from a hue palette.

The obvious workaround is to replace the NA values with a different value, such as "none". However, I feel like the default grey color for NA should get assigned even when plotting only NA values, rather than forcing the user to assign a different color (or circle around and reassign grey for the no-longer-NA values). For me, this would be the expected behavior and helpful in such cases as plotting a large number of graphs in a loop (e.g. when making a markdown report), where some data subsets have only of NA values in the color/fill variable, while others don't.

This behavior might possibly be related to this issue (even though another solution was found there): #5555

Reprex:

data.frame(x = 1:10, y = 11:20, color = "NA") %>%  # this works as expected
    ggplot(aes(x = x, y = y, color = color)) +
    geom_line()

data.frame(x = 1:10, y = 11:20, color = NA) %>%  # this throws an error
    ggplot(aes(x = x, y = y, color = color)) +
    geom_line()

Note that the same can be observed for the fill aesthetic. geom_line() is merely there for illustrative purposes, as the error occurs in ggplot()

@TimBMK TimBMK changed the title Must request at least one colour from a hue palette when plotting NA values Error: Must request at least one colour from a hue palette when plotting NA values Jan 3, 2024
@teunbrand
Copy link
Collaborator

Thanks for the report, I can reproduce the bug and agree with you that the scale's na.value should be applied in this case.
I don't think the linked issue is closely related to this one.

@teunbrand teunbrand added bug an unexpected problem or unintended behavior scales 🐍 labels Jan 3, 2024
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 scales 🐍
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants