-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Change in behaviour of manual scales in release candidate #3727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
(it looks like this changed in #3579) |
I think the old behaviour should be kept (i.e. uneven length of values and breaks). I'm not really in to #3579 so I won't propose how we solve it while keeping the value matching |
I have a few minutes this morning...I'll see if it's possible to replace |
I'm not sure that the issue it solved (#2429) was ever a problem...people should have been using From the previous version of ggplot2: library(ggplot2)
df <- data.frame(x = c("data_red", "data_black"))
p <- ggplot(df, aes(x, 1, fill = x)) +
geom_col()
p + scale_fill_manual(values = c("red", "black"),
limits = c("data_red", "data_black")) Maybe a documentation note to this effect is better than the changes in #3579? |
I guess |
I think this is a simple oversight. We need at least as many values as breaks, but having more values is ok. This should be easy to fix. I'll give it a shot this morning. |
I've made the PR. It simply replaces |
Is it allowed in master? (More breaks than values, that is) |
Master and RC behave exactly the same currently. I think the better comparison is named vs. unnamed values, as the error is only triggered by unnamed values. For named values, you can have either more or fewer breaks than values, it doesn't matter. The only thing that matters is that you don't have fewer values than limits. So, I think the behavior for unnamed values should match this. I'll amend my PR. library(ggplot2)
df <- data.frame(x = 1:3, y = 1:3, z = letters[1:3])
ggplot(df, aes(x, y, col = z)) +
geom_point() +
scale_colour_manual(
values = c(a = "red", b = "green", c = "blue"),
breaks = letters[1:4],
limits = letters[1:3]
) df <- data.frame(x = 1:3, y = 1:3, z = letters[1:3])
ggplot(df, aes(x, y, col = z)) +
geom_point() +
scale_colour_manual(
values = c("red", "green", "blue"),
breaks = letters[1:4],
limits = letters[1:3]
)
#> Error: Too many breaks for the number of values in manual scale.
#> 3 values provided compared to 4 breaks. Created on 2020-01-13 by the reprex package (v0.3.0) |
I've updated the PR. Reprex for the latest version. I think this completely matches the behavior of the current release. library(ggplot2)
df <- data.frame(x = 1:3, y = 1:3, z = letters[1:3])
# fewer breaks than limits works
ggplot(df, aes(x, y, col = z)) +
geom_point() +
scale_colour_manual(
values = c("red", "green", "blue"),
breaks = letters[1:2],
limits = letters[1:3]
) # more breaks than limits works
ggplot(df, aes(x, y, col = z)) +
geom_point() +
scale_colour_manual(
values = c("red", "green", "blue"),
breaks = letters[1:4],
limits = letters[1:3]
) # only get an error if we request more limits than values
# this was always the case
ggplot(df, aes(x, y, col = z)) +
geom_point() +
scale_colour_manual(
values = c("red", "green", "blue"),
breaks = letters[1:2],
limits = letters[1:4]
)
#> Error: Insufficient values in manual scale. 4 needed but only 3 provided. Created on 2020-01-13 by the reprex package (v0.3.0) |
* fix #3727 * remove error entirely
In previous ggplot2 versions, the following was valid:
In the release candidate, it errors (revdep failures on at least auditor, ezplot, GDCRNATools, ggmuller, obAnalytics, RAM)
Shouldn't the number of values line up with the number
limits
instead of thebreaks
? Otherwise, how would you map colours and not include them on the guide (niche behaviour, but it's possible with other colour scales)?The text was updated successfully, but these errors were encountered: