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
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."
scale_*_manual() scales do some very odd things...they pretty much only work as expected when the number of values is the same length as the limits. They use scales::manual_pal(), which might not return the right named values when limits is too small, and as you've noted, an error is thrown when the limits are longer than the manual palette provided.
In the help documentation for
scale_manual()
, the values portion states: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:
ggplot2/tests/testthat/test-scale-manual.r
Line 38 in 92d2777
You could provide a sufficient number of (non-matching) values and avoid the error.
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
The text was updated successfully, but these errors were encountered: