Skip to content

geom_pointrange() passes on na.rm - #5266

Merged
teunbrand merged 1 commit into
tidyverse:mainfrom
teunbrand:pointrange_narm
Apr 15, 2023
Merged

teunbrand merged 1 commit into
tidyverse:mainfrom
teunbrand:pointrange_narm

Conversation

@teunbrand

Copy link
Copy Markdown
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 thread R/geom-pointrange.R
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
Copy Markdown
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

@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

@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