You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect warning from geom about missing values when scale sets limits, unless data is filtered first #5250
# also happens with other geoms:d|>
ggplot(aes(x=yr, y=value, colour=animal)) +
geom_point() +
scale_x_continuous(limits= c(2011, 2020))
#> Warning: Removed 22 rows containing missing values (`geom_point()`).
# Warning goes away if data is explicitly filtered to match the scale limits:d|>
filter(yr>=2011) |>
ggplot(aes(x=yr, y=value, colour=animal)) +
geom_line() +
scale_x_continuous(limits= c(2011, 2020))
This has been the intended behavior for as long as I can remember (over a decade?). ggplot warns you when the scale range is smaller than the data range. The warning goes away if you set na.rm = TRUE in the geom:
I agree that the wording of the warning is a bit confusing, but the warning itself is useful. Not sure if it would be possible to catch the specific situation (data values outside the scale limits) and give a different warning in that case, versus other reasons why there may be missing values.
I agree that the warning is useful and appropriate, but perhaps the wording could be improved.
The censoring itself occurs in the scales, which doesn't know about in what layer it is censoring data. The dropping of the data occurs in the layers, which don't know whether they see NAs because they were missing from the beginning, or censored by the out-of-bounds handler. This makes it a bit hard to signal a tailored error message.
Instead, we might just update the wording so that it reflects the possibility of censored data:
Activity
clauswilke commentedon Mar 27, 2023
This has been the intended behavior for as long as I can remember (over a decade?). ggplot warns you when the scale range is smaller than the data range. The warning goes away if you set
na.rm = TRUEin the geom:Created on 2023-03-27 with reprex v2.0.2
I agree that the wording of the warning is a bit confusing, but the warning itself is useful. Not sure if it would be possible to catch the specific situation (data values outside the scale limits) and give a different warning in that case, versus other reasons why there may be missing values.
teunbrand commentedon Mar 27, 2023
I agree that the warning is useful and appropriate, but perhaps the wording could be improved.
The censoring itself occurs in the scales, which doesn't know about in what layer it is censoring data. The dropping of the data occurs in the layers, which don't know whether they see
NAs because they were missing from the beginning, or censored by the out-of-bounds handler. This makes it a bit hard to signal a tailored error message.Instead, we might just update the wording so that it reflects the possibility of censored data: