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

na.rm = NA default for geom_waffle() gives an error #95

Closed
mine-cetinkaya-rundel opened this issue Apr 16, 2023 · 5 comments
Closed

na.rm = NA default for geom_waffle() gives an error #95

mine-cetinkaya-rundel opened this issue Apr 16, 2023 · 5 comments

Comments

@mine-cetinkaya-rundel
Copy link

Running the example for geom_waffle() shows that the default for na.rm no longer works:

data.frame(
  parts = factor(rep(month.abb[1:3], 3), levels=month.abb[1:3]),
  vals = c(10, 20, 30, 6, 14, 40, 30, 20, 10),
  fct = c(rep("Thing 1", 3), rep("Thing 2", 3), rep("Thing 3", 3))
) -> xdf

ggplot(xdf, aes(fill = parts, values = vals)) +
  geom_waffle() +
  facet_wrap(~fct)
#> Error in ggplot(xdf, aes(fill = parts, values = vals)): could not find function "ggplot"

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

The default below should be set to TRUE or FALSE:

na.rm = NA, show.legend = NA,

I believe this is due to:

ggplot2:::check_bool(NA)
#> Error:
#> ! `NA` must be `TRUE` or `FALSE`, not `NA`.
#> ---
#> Backtrace:
#>     ▆
#>  1. └─ggplot2:::check_bool(NA)
#>  2.   └─ggplot2:::stop_input_type(...)
#>  3.     └─rlang::abort(message, ..., call = call, arg = arg)
@linshhhhh
Copy link

Hi! I just encountered the same problem. It gives an error in remove_missing(): because "na.rm must be TRUE or FALSE, not NA". Have you figured out the solution to this error? Thank you in advance!

@mine-cetinkaya-rundel
Copy link
Author

@linshhhhh you can set geom_waffle(na.rm = TRUE) or geom_waffle(na.rm = FALSE) explicitly and it should work.

@linshhhhh
Copy link

Thank you so much for your help. It works finally!

@AnttiRask
Copy link

AnttiRask commented Aug 29, 2023

To recreate the exact sample plot, this is the complete code. If someone would like to update the documentation with these.

library(dplyr)
library(waffle)

storms_df <- storms %>% 
    filter(
        status %in% c("tropical storm", "tropical depression", "hurricane"),
        between(year, 2010, 2015)
    ) %>% 
    count(year, status)

storms_df %>% 
    ggplot(aes(fill = status, values = n)) +
    geom_waffle(
        color  = "white",
        size   = .25,
        n_rows = 10,
        flip   = TRUE,
        na.rm  = TRUE
    ) +
    facet_wrap(~year, nrow = 1, strip.position = "bottom") +
    scale_x_discrete() + 
    scale_y_continuous(labels = function(x) x * 10, # make this multiplyer the same as n_rows
                       expand = c(0,0)) +
    ggthemes::scale_fill_tableau(name=NULL) +
    coord_equal() +
    labs(
        title = "Faceted Waffle Bar Chart",
        subtitle = "{dplyr} storms data",
        x = "Year",
        y = "Count"
    ) +
    theme_minimal(base_family = "Roboto Condensed") +
    theme(panel.grid = element_blank(), axis.ticks.y = element_line()) +
    guides(fill = guide_legend(reverse = TRUE))

@hrbrmstr
Copy link
Owner

fixed in latest GH and now CRAN release. #ty

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

4 participants