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

'geom_rangeframe' does not draw range lines when there is missing data #177

Open
pn317 opened this issue May 8, 2024 · 0 comments
Open

Comments

@pn317
Copy link

pn317 commented May 8, 2024

The help file for geom_rangeframe indicates that if na.rm = FALSE then NAs will be removed with a warning, and if na.rm = TRUE then NAs will be removed silently.

However, it seems that when NAs are present, there is no warning and the range lines are not drawn at all.

I think it is because x and y are specified as optional_aes in GeomRangeFrame, but the default Geom$handle_na only checks the required_aes and non_missing_aes.

I have a fix that I could submit as a pull request if this can be replicated.

Example below adapted from geom_point ...

library("dplyr")
library("ggplot2")
library("ggthemes")
library("magrittr")

set.seed(1)
mtcars2 <- mtcars %>%
  mutate(mpg = ifelse(runif(32) < 0.2, NA, mpg))

# generates a warning from geom_point 
# but not from geom_rangeframe
# and range line for mpg not drawn
mtcars2 %>%
  ggplot(aes(wt, mpg)) +
  geom_point() +
  coord_cartesian(clip = "off") +
  geom_rangeframe()

# suppresses the warning from geom_point
# range line for mpg still not drawn
mtcars2 %>%
  ggplot(aes(wt, mpg)) +
  geom_point(na.rm = TRUE) +
  coord_cartesian(clip = "off") +
  geom_rangeframe(na.rm = TRUE)

# explicitly removing all NAs "works"
# both range lines are drawn
mtcars2 %>%
  filter(complete.cases(.)) %>%
  ggplot(aes(wt, mpg)) +
  geom_point() +
  coord_cartesian(clip = "off") +
  geom_rangeframe()

My sessionInfo() ...

R version 4.3.0 (2023-04-21 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=English_United Kingdom.utf8  LC_CTYPE=English_United Kingdom.utf8    LC_MONETARY=English_United Kingdom.utf8
[4] LC_NUMERIC=C                            LC_TIME=English_United Kingdom.utf8    

time zone: Europe/London
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] magrittr_2.0.3 ggthemes_5.1.0 ggplot2_3.5.1  dplyr_1.1.4   

loaded via a namespace (and not attached):
 [1] vctrs_0.6.5       cli_3.6.2         rlang_1.1.3       stringi_1.8.4     purrr_1.0.2       generics_0.1.3    glue_1.7.0       
 [8] labeling_0.4.3    colorspace_2.1-0  scales_1.3.0      fansi_1.0.6       grid_4.3.0        munsell_0.5.1     tibble_3.2.1     
[15] lifecycle_1.0.4   stringr_1.5.1     compiler_4.3.0    pkgconfig_2.0.3   rstudioapi_0.16.0 farver_2.1.1      R6_2.5.1         
[22] tidyselect_1.2.1  utf8_1.2.4        pillar_1.9.0      tools_4.3.0       withr_3.0.0       gtable_0.3.5 
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

No branches or pull requests

1 participant