Description
In the help documentation for scale_manual()
, the values portion states:
values "a set of aesthetic values to map data values to. If this is a named vector, then the values will be matched based on the names. If unnamed, values will be matched in order (usually alphabetical) with the limits of the scale. Any data values that don't match will be given na.value."
Given this definition, I was surprised that an error was still thrown in the following situation:
For discrete scales, regardless of whether the actual values match, if there are too few values provided, the "Insufficient Values" error is thrown, as in the test below:
You could provide a sufficient number of (non-matching) values and avoid the error.
df <- data.frame(x = 1, y = 1:3, z = factor(c("a","b", NA), exclude = NULL))
p <- qplot(x, y, data = df, colour = z)
# Case 1: Insufficient values error (as expected)
ggplot_build(p + scale_colour_manual(values = c("a" = "black")))
# Case 2: Insufficient values error (not as expected)
ggplot_build(p + scale_colour_manual(values = c("a" = "black"), na.value="grey"))
# Case 3: plot with "b" points given na.value (as expected)
ggplot_build(p + scale_colour_manual(values = c("a" = "black", "c" = "white"), na.value="grey"))
I was expecting an error if na.value
was not specified (Case 1).
I was NOT expecting an error if na.value
WAS specified (Case 2).
My thinking being that case 2 and case 3 are doing basically the same thing but Case 3 has some arbitrary extra value(s) added simply to match the number of values. I'm not sure what was intended, but seems to me that if na.value
is provided, the number of values given shouldn't really matter because "Any data values that don't match will be given na.value."
Related to #2428