Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Wrong error message with NA name in scale_linetype_manual, inconsistent with scale_color_manual #2206
Comments
|
It does seem like linetype should behave the same as colour here. Below is a more minimal example. In the future it's helpful if you can make your example as minimal as possible to isolate the problem. library("scales")
library("ggplot2")
## Classes in the data
lvls <- levels(economics_long$variable)
## Vectors of colors and linetypes
colors <- viridis_pal()(length(lvls))
types <- c("solid", "dashed", "dotted", "dotdash", "longdash")
## Add one too few names
names(colors) <- lvls[-1]
names(types) <- lvls[-1]
colors
#> pop psavert uempmed unemploy <NA>
#> "#440154FF" "#3B528BFF" "#21908CFF" "#5DC863FF" "#FDE725FF"
types
#> pop psavert uempmed unemploy <NA>
#> "solid" "dashed" "dotted" "dotdash" "longdash"
ggplot(economics_long, aes(date, value01, colour = variable)) +
geom_line() +
scale_colour_manual(values = colors)ggplot(economics_long, aes(date, value01, linetype = variable)) +
geom_line() +
scale_linetype_manual(values = types)
#> Error in grid.Call.graphics(C_lines, x$x, x$y, index, x$arrow): invalid hex digit in 'color' or 'lty' |
karawoo
added bug scales
labels
Jul 14, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

jsams commentedJul 14, 2017
When NAs are included as a name with the scale_linetype_manual, an incorrect error occurs:
The error says that the linetype or color given is invalid even when all colors and linetypes are in fact valid. The problem is with an NA in the names of the value vector given to the scale_linetype_manual function.
However, the same vector of names with colors (with color identifiers rather than linetype identifiers) does not produce an error (although the line does not get drawn either).
It seems as if an NA value is given a specific linetype, then the line should be drawn. Even if you disagree, the error message given should point the user at the correct problem, an NA in the names, and not send them down a rabbit hole trying to diagnose a non-problem.
Here is some code that demonstrates both the inconsistent behavior and the error