Closed
Description
In previous ggplot2 versions, the following was valid:
library(ggplot2)
df <- data.frame(x = 1:3, y = 1:3)
ggplot(df, aes(x, y, col = factor(x))) +
geom_point() +
scale_colour_manual(values = c("red", "green", "blue", "teal"), breaks = factor(1))In the release candidate, it errors (revdep failures on at least auditor, ezplot, GDCRNATools, ggmuller, obAnalytics, RAM)
library(ggplot2)
df <- data.frame(x = 1:3, y = 1:3)
ggplot(df, aes(x, y, col = factor(x))) +
geom_point() +
scale_colour_manual(values = c("red", "green", "blue", "teal"), breaks = factor(1))
#> Error: Differing number of values and breaks in manual scale.
#> 4 values provided compared to 1 breaks.Shouldn't the number of values line up with the number limits instead of the breaks? Otherwise, how would you map colours and not include them on the guide (niche behaviour, but it's possible with other colour scales)?
Metadata
Metadata
Assignees
Labels
No labels

Activity
paleolimbot commentedon Jan 13, 2020
(it looks like this changed in #3579)
thomasp85 commentedon Jan 13, 2020
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
paleolimbot commentedon Jan 13, 2020
I have a few minutes this morning...I'll see if it's possible to replace
breakswithlimitsfrom the changes in that PR.paleolimbot commentedon Jan 13, 2020
I'm not sure that the issue it solved (#2429) was ever a problem...people should have been using
limitsinstead ofbreaks.From the previous version of ggplot2:
Maybe a documentation note to this effect is better than the changes in #3579?
yutannihilation commentedon Jan 13, 2020
I guess
limitsdidn't work for unnamedvaluesbefore #3685.clauswilke commentedon Jan 13, 2020
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.
fix tidyverse#3727
clauswilke commentedon Jan 13, 2020
I've made the PR. It simply replaces
!=with>in the check before the error. I don't see a meaningful way of having more breaks than values, but please let me know if you think this case should also be allowed.thomasp85 commentedon Jan 13, 2020
Is it allowed in master? (More breaks than values, that is)
clauswilke commentedon Jan 13, 2020
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.
Created on 2020-01-13 by the reprex package (v0.3.0)
clauswilke commentedon Jan 13, 2020
I've updated the PR. Reprex for the latest version. I think this completely matches the behavior of the current release.
Created on 2020-01-13 by the reprex package (v0.3.0)
Allow more values than breaks in manual scale (#3728)