Skip to content

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

Closed
@trevorld

Description

@trevorld
  • 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")'

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions