Skip to content

Bug: where facet variable is character & drop = F #5485

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

Closed
davidhodge931 opened this issue Oct 15, 2023 · 0 comments · Fixed by #5847
Closed

Bug: where facet variable is character & drop = F #5485

davidhodge931 opened this issue Oct 15, 2023 · 0 comments · Fixed by #5847

Comments

@davidhodge931
Copy link

This is pretty minor, as users shouldn't use drop = F if variable is character - but still be nice if it worked anyway, as does scale_*_discrete(..., drop = F) with characters

library(tidyverse)
#> Warning: package 'purrr' was built under R version 4.3.1
#> Warning: package 'dplyr' was built under R version 4.3.1
#> Warning: package 'lubridate' was built under R version 4.3.1
library(palmerpenguins)

#bugs if character & drop = F  
penguins |>
  mutate(sex = as.character(sex)) |>
  ggplot() +
  geom_point(aes(x = body_mass_g, y = flipper_length_mm)) +
  facet_wrap(~sex, drop = F)
#> Error in `scale_apply()`:
#> ! `scale_id` must not contain any "NA"
#> Backtrace:
#>      ▆
#>   1. ├─base::tryCatch(...)
#>   2. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#>   3. │   ├─base (local) tryCatchOne(...)
#>   4. │   │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#>   5. │   └─base (local) tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
#>   6. │     └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>   7. │       └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#>   8. ├─base::withCallingHandlers(...)
#>   9. ├─base::saveRDS(...)
#>  10. ├─base::do.call(...)
#>  11. ├─base (local) `<fn>`(...)
#>  12. └─global `<fn>`(input = base::quote("sour-puppy_reprex.R"))
#>  13.   └─rmarkdown::render(input, quiet = TRUE, envir = globalenv(), encoding = "UTF-8")
#>  14.     └─knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
#>  15.       └─knitr:::process_file(text, output)
#>  16.         ├─base::withCallingHandlers(...)
#>  17.         ├─base::withCallingHandlers(...)
#>  18.         ├─knitr:::process_group(group)
#>  19.         └─knitr:::process_group.block(group)
#>  20.           └─knitr:::call_block(x)
#>  21.             └─knitr:::block_exec(params)
#>  22.               └─knitr:::eng_r(options)
#>  23.                 ├─knitr:::in_input_dir(...)
#>  24.                 │ └─knitr:::in_dir(input_dir(), expr)
#>  25.                 └─knitr (local) evaluate(...)
#>  26.                   └─evaluate::evaluate(...)
#>  27.                     └─evaluate:::evaluate_call(...)
#>  28.                       ├─evaluate (local) handle(...)
#>  29.                       │ └─base::try(f, silent = TRUE)
#>  30.                       │   └─base::tryCatch(...)
#>  31.                       │     └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#>  32.                       │       └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  33.                       │         └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#>  34.                       ├─base::withCallingHandlers(...)
#>  35.                       ├─base::withVisible(value_fun(ev$value, ev$visible))
#>  36.                       └─knitr (local) value_fun(ev$value, ev$visible)
#>  37.                         └─knitr (local) fun(x, options = options)
#>  38.                           ├─base::withVisible(knit_print(x, ...))
#>  39.                           ├─knitr::knit_print(x, ...)
#>  40.                           └─knitr:::knit_print.default(x, ...)
#>  41.                             └─evaluate (local) normal_print(x)
#>  42.                               ├─base::print(x)
#>  43.                               └─ggplot2:::print.ggplot(x)
#>  44.                                 ├─ggplot2::ggplot_build(x)
#>  45.                                 └─ggplot2:::ggplot_build.ggplot(x)
#>  46.                                   └─layout$train_position(data, scale_x(), scale_y())
#>  47.                                     └─ggplot2 (local) train_position(..., self = self)
#>  48.                                       └─self$facet$train_scales(...)
#>  49.                                         └─ggplot2 (local) train_scales(...)
#>  50.                                           └─ggplot2:::scale_apply(layer_data, x_vars, "train", SCALE_X, x_scales)
#>  51.                                             └─cli::cli_abort("{.arg scale_id} must not contain any {.val NA}")
#>  52.                                               └─rlang::abort(...)

#works if factor
penguins |>
  ggplot() +
  geom_point(aes(x = body_mass_g, y = flipper_length_mm)) +
  facet_wrap(~sex, drop = F)
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_point()`).

Created on 2023-10-16 with reprex v2.0.2

@davidhodge931 davidhodge931 changed the title Bug if facet variable is character & drop = F argument used in facet_* Bug: where facet variable is character & drop = F argument used in facet_* Nov 25, 2023
@davidhodge931 davidhodge931 changed the title Bug: where facet variable is character & drop = F argument used in facet_* Bug: where facet variable is character & drop = F Nov 25, 2023
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 a pull request may close this issue.

1 participant