8000
Skip to content

Fix geom_ribbon(na.rm) - #6244

Merged
teunbrand merged 3 commits into
tidyverse:mainfrom
teunbrand:geom_ribbon_narm
Dec 17, 2024
Merged

Fix geom_ribbon(na.rm)#6244
teunbrand merged 3 commits into
tidyverse:mainfrom
teunbrand:geom_ribbon_narm

Conversation

@teunbrand
@teunbrand teunbrand commented Dec 17, 2024
Copy link
Copy Markdown
Collaborator

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

@thomasp85 thomasp85 left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

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

0