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

Allow pattern_fill (and more) to take a **list** of (color) vectors #100

Closed
Tracked by #104
trevorld opened this issue Jun 23, 2023 · 2 comments · Fixed by #103
Closed
Tracked by #104

Allow pattern_fill (and more) to take a **list** of (color) vectors #100

trevorld opened this issue Jun 23, 2023 · 2 comments · Fixed by #103
Assignees
Labels
enhancement New feature or request

Comments

@trevorld
Copy link
Owner

trevorld commented Jun 23, 2023

  • It looks like it is possible for pattern_fill (and more) to be passed a list of values but right now {ggpattern} and {gridpattern} aren't setup to accept such input.
  • This should allow "native" support for multi-colored and/or multi-shaped patterns without needing to resort to any custom pattern tricks
library("ggplot2")
library("ggpattern")
df <- data.frame(level = c("a", "b", "c", 'd'), outcome = c(2.3, 1.9, 3.2, 1))
ggplot(df) +
  geom_col_pattern(
    aes(level, outcome, fill = level), 
    pattern = 'stripe',
    pattern_fill    = list('white', 'white', c('white', 'grey'), 'grey'),
    colour  = 'black'
  ) +
  theme_bw(18) +
  theme(legend.position = 'none') + 
  labs(
    title    = "ggpattern::geom_col_pattern()",
    subtitle = "pattern = 'stripe'"
  ) +
  coord_fixed(ratio = 1/2)
Error in grDevices::col2rgb(colour, alpha = TRUE) : 
  invalid color name 'c("white", "grey")'
@trevorld trevorld added the enhancement New feature or request label Jun 23, 2023
@trevorld trevorld self-assigned this Jun 23, 2023
trevorld added a commit that referenced this issue Oct 4, 2023
* Each pattern aesthetic may now be a list of vectors with each list element
  providing that aesthetic for a different pattern (#100).
  Most builtin `{gridpattern}` "geometry" patterns support multiple fill colors etc. which previously we could only access in `{ggpattern}` via custom patterns.
* We remove the multi-color stripe custom pattern example from developing
  patterns vignette.  With this update we don't need a custom serialization pattern anymore
  to have multi-color stripe patterns.

closes #100
This was referenced Oct 4, 2023
@trevorld
Copy link
Owner Author

trevorld commented Oct 6, 2023

Currently we "solve this" with the following:

args <- lapply(as.list(params), unlist)

And in basic examples this seems to work fine.

However in next version of {ggplot2} we might perhaps expect certain params to be lists of grid patterns for e.g. fill which me might not want to unlist()? Perhaps instead we want a helper functions that extracts the first element of length-one lists?

Also, would we want to explicitly support pattern_fill being patterns as well?

@trevorld
Copy link
Owner Author

Instead of just colors we may want to also allow lists of grid patterns...

trevorld added a commit that referenced this issue Apr 17, 2024
* Each pattern aesthetic may now be a list of vectors with each list element
  providing that aesthetic for a different pattern (#100).
  Most builtin `{gridpattern}` "geometry" patterns support multiple fill colors etc. which previously we could only access in `{ggpattern}` via custom patterns.
* We remove the multi-color stripe custom pattern example from developing
  patterns vignette.  With this update we don't need a custom serialization pattern anymore
  to have multi-color stripe patterns.

closes #100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant