Closed
Description
Similarly to GeomBar
and GeomCol
that use GeomRect
to draw, I believe GeomTile
too should declare a non_missing_aes
member for xmin, xmax, ymin, ymax variables.
For example in GeomBar
I see this:
# These aes columns are created by setup_data(). They need to be listed here so
# that GeomRect$handle_na() properly removes any bars that fall outside the defined
# limits, not just those for which x and y are outside the limits
non_missing_aes = c("xmin", "xmax", "ymin", "ymax"),
I stumbled to this, using geom_bin2d
(which uses GeomTile
) where it may produce data with NA in any of xmin, xmax, ymin, ymax. Here is a reprex showing that result grob contains NAs.
library(ggplot2)
p <- ggplot(diamonds, aes(x, y)) + xlim(4, 10) + ylim(4, 10) + geom_bin2d()
g <- layer_grob(p, 1)[[1]]
#> Warning: Removed 478 rows containing non-finite values (stat_bin2d).
any(is.na(g$x)|is.na(g$y))
#> [1] TRUE
Created on 2021-05-18 by the reprex package (v2.0.0)
Adding the non_missing_aes
fixes this.