Open sebneus opened 1 year ago
Unfortuneatly @teunbrand 's fix does not quite cut
π it for scale_x_binned
. See also this example:
library(ggplot2)
ggplot(data.frame(x=1), aes(x=x)) + geom_bar() + scale_x_binned(limits = c(0,1))
ggplot(data.frame(x=1), aes(x=x)) + geom_bar() + scale_x_binned()
#> Error in cut.default(x, all_breaks, labels = FALSE, include.lowest = TRUE, : invalid number of intervals
Created on 2023-08-03 by the reprex package (v2.0.1)
So as a workaround you can specify limits for the binned scale yourself.
I am afraid this issue isn't too much an implementation problem but rather a design question. It is not clear to me how a binned scale should behave without predefined breaks, but I am under the impression that in many cases we don't actually want a scale_x_binned
but a scale_x_integer
or scale_x_binned_integer
?
I want to print a couple of ggplots in a group_walk loop. But one of the plots only returns values in one bin which resolves in an error.
Here is an example:
Created on 2022-11-29 with reprex v2.0.2
If there is a bin with a at least two different numbers (here 1 and 2), the plot succeeds:
Created on 2022-11-29 with reprex v2.0.2
If I remove the
scale_fill_binned()
part the chart is drawn, but with no color steps. Similar (but different) error is thrown if I useguides(fill = "colorsteps")
. Usinggeom_tile(aes(x, y, fill = after_stat(count)), stat = "bin2d")
shows the same behaviour.ggplot version is 3.4.0.
Regards SebNeu