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:
library(ggplot2)
data.frame(x = c("a", "b"),
y = c("A", "B")) |>
ggplot() +
geom_tile(aes(x = x, y = y, fill = after_stat(count)), stat = "bin2d") +
scale_fill_binned()
#> Error in cut.default(x, breaks, labels = FALSE, include.lowest = TRUE, : ungültige Anzahl von Intervallen
Created on 2022-11-28 with reprex v2.0.2
If there is a bin with a different number, the plot succeeds:
library(ggplot2)
data.frame(x = c("a", "b", "b"),
y = c("A", "B", "B")) |>
ggplot() +
geom_tile(aes(x = x, y = y, fill = after_stat(count)), stat = "bin2d") +
scale_fill_binned()
Created on 2022-11-28 with reprex v2.0.2
Is this a ggplot2 bug? What can I do to get around it?
Regards
SebNeu