You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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()
The text was updated successfully, but these errors were encountered:
TimBMK
changed the title
Must request at least one colour from a hue palette when plotting NA valuesError: Must request at least one colour from a hue palette when plotting NA values
Jan 3, 2024
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.
When using the
color
orfill
aesthetics on a variable with onlyNA
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 onlyNA
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 ofNA
values in thecolor
/fill
variable, while others don't.This behavior might possibly be related to this issue (even though another solution was found there): #5555
Reprex:
Note that the same can be observed for the
fill
aesthetic.geom_line()
is merely there for illustrative purposes, as the error occurs inggplot()
The text was updated successfully, but these errors were encountered: