Skip to content

geom_pointrange() passes on na.rm #5266

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

Merged
merged 1 commit into from
Apr 15, 2023

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #5261.

It now passes on the na.rm parameter to downstream drawing functions.

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

# Based on example from docs
df <- data.frame(
  trt = factor(c(1, 1, 2, 2)),
  resp = c(1, 5, 3, 4),
  group = factor(c(1, 2, 1, 2)),
  upper = c(1.1, NA_real_, 3.3, NA_real_),
  lower = c(0.8, NA_real_, 2.4, NA_real_)
)

p <- ggplot(df, aes(trt, resp, colour = group))

# Throws warning
p + geom_pointrange(aes(ymin = lower, ymax = upper), na.rm = FALSE)
#> Warning: Removed 2 rows containing missing values (`geom_segment()`).

# Stays silent
p + geom_pointrange(aes(ymin = lower, ymax = upper), na.rm = TRUE)

Created on 2023-04-12 with reprex v2.0.2

Comment on lines +52 to +55
line_grob <- GeomLinerange$draw_panel(
data, panel_params, coord, lineend = lineend, flipped_aes = flipped_aes,
na.rm = na.rm
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Preconstructed here to avoid code duplication

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 ca9fd2e into tidyverse:main Apr 15, 2023
@teunbrand teunbrand deleted the pointrange_narm branch April 15, 2023 05:12
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.

Inconsistent treatment of na.rm = TRUE in geom_pointrange
2 participants