Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix geom_ribbon(na.rm) #6244

Merged
merged 3 commits into from
Dec 17, 2024
Merged

Fix geom_ribbon(na.rm) #6244

merged 3 commits into from
Dec 17, 2024

Conversation

teunbrand
Copy link
Collaborator

@teunbrand teunbrand commented Dec 17, 2024

This PR aims to fix #6243.

Briefly, missing values are thrown out and warn about when na.rm = FALSE.
The warning is skipped when na.rm = TRUE but missing values are thrown out.
When throwing out missing values, the group aesthetic is reformed so that groups with NA values break up into new uninterrupted groups.

Reprex from issue, note gradient is uniform now:

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

df <- data.frame(
  x = c(1:3, 1:3),
  ymin = c(1, 1, 1, NA, 2, 2),
  ymax = c(1.5, 2, 1.5, 2.5, 3, 2.5),
  group = c(1,1,1,2,2,2)
)

ggplot(df, aes(x, ymin = ymin, ymax = ymax, group = group, fill = x)) +
  geom_ribbon() +
  scale_fill_viridis_c()
#> Warning: Removed 1 row containing missing values or values outside the scale range
#> (`geom_ribbon()`).

Created on 2024-12-17 with reprex v2.1.1

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand teunbrand merged commit efc53cc into tidyverse:main Dec 17, 2024
13 checks passed
@teunbrand teunbrand deleted the geom_ribbon_narm branch December 17, 2024 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quirky NA-handling of geom_ribbon()
2 participants