trevorld / ggpattern

ggplot geoms with pattern fills
https://trevorldavis.com/R/ggpattern/dev/
Other
356 stars 18 forks source link

ERROR thrown when trying to draw key for missing pattern #107

Closed davidhodge931 closed 2 months ago

davidhodge931 commented 6 months ago
library(ggplot2)
library(ggpattern)

df <- data.frame(x = c(1, 2, 3), y = c(1, 2, NA), fill = c("A", "B", NA))

ggplot(df, aes(x, y, fill = fill, pattern = fill)) +
  geom_col_pattern(position = 'identity')
#> Warning: The `scale_name` argument of `discrete_scale()` is deprecated as of ggplot2
#> 3.5.0.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.
#> Warning: Removed 1 row containing missing values or values outside the scale range
#> (`geom_col_pattern()`).
#> Error in if (pat == "regular_polygon" && is.numeric(params$pattern_shape)) params$pattern_shape <- "convex6": missing value where TRUE/FALSE needed

Created on 2024-01-15 with reprex v2.1.0

trevorld commented 6 months ago

ggpattern doesn't seem to work with DEV ggplot2

Are you sure this is an issue with the release/development version of {ggplot2}?

The issue to me seems to arise when trying to draw a legend for an NA pattern (instead of the "none" pattern) which {ggpattern} doesn't seem to be able to handle.

trevorld commented 6 months ago
davidhodge931 commented 6 months ago

I initially raised this issue on ggplot2, and the authors there suggested a fix might be to set a default na value

https://github.com/tidyverse/ggplot2/issues/5608

trevorld commented 6 months ago

the authors there suggested a fix might be to set a default na value

I'll look into setting a default na.value = "none" for scale_pattern_discrete()