-
Notifications
You must be signed in to change notification settings - Fork 2.1k
scale_fill_steps produces error when both breaks and labels are specified #4548
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
This could be related to this recent bugfix: After this fix, the labels for the boundaries of the colorscale disappeared, so the number of default labels changed... |
Can you please provide a minimal reprex (reproducible example)? The goal of a reprex is to make it as easy as possible for me to recreate your problem so that I can fix it: please help me help you! If you've never heard of a reprex before, start by reading about the reprex package, including the advice further down the page. Please make sure your reprex is created with the reprex package as it gives nicely formatted output and avoids a number of common pitfalls. |
Here you go: library(ggplot2)
data = data.frame(expand.grid(x = 1:10,y = 1:10),fill = 1:100)
# this works:
ggplot(data) + geom_tile(aes(x=x,y=y,fill = fill)) + scale_fill_steps() # this doesn't work, although it should (I think):
breaks = seq(0,100,length.out = 5)
labels = breaks
ggplot(data) + geom_tile(aes(x=x,y=y,fill = fill)) + scale_fill_steps(breaks = breaks,labels = labels)
#> Error: Breaks and labels are different lengths Created on 2022-03-17 by the reprex package (v2.0.1) |
Thanks. I've made it a little more minimal to make it easier to track down the problem: library(ggplot2)
data <- data.frame(x = 1:3)
ggplot(data) +
geom_col(aes(x, x, fill = x)) +
scale_fill_steps(breaks = 1:2, labels = 1:2)
#> Error in `f()`:
#> ! Breaks and labels are different lengths Created on 2022-03-17 by the reprex package (v2.0.1) |
It seems this is already fixed in the dev version (probably by #4849?). library(ggplot2)
data <- data.frame(x = 1:3)
ggplot(data) +
geom_col(aes(x, x, fill = x)) +
scale_fill_steps(breaks = 1:2, labels = 1:2) Created on 2022-07-23 by the reprex package (v2.0.1) |
When using
scale_fill_steps
orscale_fill_steps2
, specifying two equal-length vectors as breaks and labels leads to an error.I am getting the error message 'Error: Breaks and labels are different lengths'.
I tried to find out which number of labels it expects, and ran this:
This printed out the numbers from 2 to 10 excluding 5, which I don't understand because setting i to 5 and running the function passed to tryCatch manually does result in an error.
The text was updated successfully, but these errors were encountered: