Skip to content

Inconsistent treatment of na.rm = TRUE in geom_pointrange #5261

Closed

Description

@robbiebatley

Hello there,

I've noticed a minor inconsistency in the treatment of na.rm=TRUE in geom_pointrange.
When all values of ymin and ymax are missing for a group, geom_pointrange(..., na.rm =TRUE) will issue a warning message.

I expected that the behaviour of geom_pointrange would be the same as geom_linerange, geom_crossbar and geom_errorbar (which currently don't issue a warning).

library(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))

# Point range complains where one colour has all missing values
p + geom_pointrange(aes(ymin = lower, ymax = upper), na.rm = TRUE)
#> Warning: Removed 2 rows containing missing values (`geom_segment()`).

# Rest of the family are all good this
p + geom_linerange(aes(ymin = lower, ymax = upper), na.rm = TRUE)

p + geom_crossbar(aes(ymin = lower, ymax = upper), na.rm = TRUE, width = 0.2)

p + geom_errorbar(aes(ymin = lower, ymax = upper), na.rm = TRUE, width = 0.2)

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

If this is a bug, I'm happy to spend some time trying to figure out how to fix it :)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions