Briefly, ulevels() was always dropping NAs, leading to data being mapped to non-existing PANELs and generating invalid scale_ids. By including NAs, we prevent these invalid scale_ids.
stat_summary_2d() was also making use of ulevels() where NAs should be dropped. Therefore, ulevels() gets an na.last argument that is propagated to sort() so we can pick when to drop NA and when not.
Reprex from issue:
devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2
library(palmerpenguins)
penguins |>
transform(sex = as.character(sex)) |>
ggplot() +
geom_point(aes(x = body_mass_g, y = flipper_length_mm)) +
facet_wrap(~sex, drop = FALSE)
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_point()`).
This PR aims to fix #5485.
Briefly,
ulevels()
was always droppingNA
s, leading to data being mapped to non-existing PANELs and generating invalidscale_id
s. By includingNA
s, we prevent these invalidscale_id
s.stat_summary_2d()
was also making use ofulevels()
whereNA
s should be dropped. Therefore,ulevels()
gets anna.last
argument that is propagated tosort()
so we can pick when to dropNA
and when not.Reprex from issue:
Created on 2024-04-18 with reprex v2.1.0