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
{{ message }}
Repository navigation
Nonexistent color names: data not displayed without throwing warning/error #3644
I would expect an error or at least a warning if color names are not correct. Now the data linked to such colors are not displayed.
I suggest using a warning which informs the user that his/her color mapping has been ignored and default color scale is used.
Here a minimal reprex using the standard example in documentation:
p<- ggplot(mtcars, aes(mpg, wt)) ++ geom_point(aes(colour=factor(cyl)))
p+ scale_colour_manual(values= c("darkred", "blue", "dark green")) #dark green instead of darkgreen
Reacted by EmmaCartuyvels1, Hans Van Calster and Jonathan Magnolia Gilligan
@thomasp85
Though I don't have a closer look at this yet, it seems scales package unintendedly became tolerant for invalid colour names after it switched to farver by r-lib/scales#224 mainly because of the difference below. Is it possible to add some option to decode_colour() to raise error when the colour name is invalid?
farver::decode_colour("foo")
#> r g b#> [1,] NA NA NAgrDevices::col2rgb("foo")
#> Error in grDevices::col2rgb("foo"): invalid color name 'foo'
...btw, this particular example gives us another surprise. Wow...
farver::decode_colour("dark green")
#> r g b#> [1,] NA NA NAgrDevices::col2rgb("darkgreen")
#> [,1]#> red 0#> green 100#> blue 0grDevices::col2rgb("dark green")
#> [,1]#> red 0#> green 100#> blue 0
Activity
yutannihilation commentedon Dec 19, 2019
@thomasp85
Though I don't have a closer look at this yet, it seems scales package unintendedly became tolerant for invalid colour names after it switched to farver by r-lib/scales#224 mainly because of the difference below. Is it possible to add some option to
decode_colour()to raise error when the colour name is invalid?Created on 2019-12-19 by the reprex package (v0.3.0)
...btw, this particular example gives us another surprise. Wow...
Created on 2019-12-19 by the reprex package (v0.3.0)
thomasp85 commentedon Dec 19, 2019
🤬 the ability to accept any number of colour name formats in
col2rgb()is just plain annoying...I'm not sure that throwing an error in farver is the best way forward though? @hadley do you have any preferences
thomasp85 commentedon Dec 19, 2019
I can get behind throwing a warning
yutannihilation commentedon Dec 19, 2019
Yeah, I agree the behavior of
col2rgb()is not fine. A warning sounds good.hadley commentedon Dec 19, 2019
Warning seems reasonable to me (although I'd also be fine with an error)
yutannihilation commentedon Dec 20, 2019
It seems this is fixed by thomasp85/farver@0360a08. Thanks @thomasp85!
Created on 2019-12-20 by the reprex package (v0.3.0)
hadley commentedon Dec 20, 2019
@thomasp85 I think the 14 warnings here suggest an error would be better
thomasp85 commentedon Dec 20, 2019
Yeah - maybe you’re right
lock commentedon Jun 24, 2020
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/