|
- read_colors <- function(file) {
- library(dplyr)
- text <- readLines(file, warn = FALSE) %>%
- stringr::str_subset("#[0-9a-fA-F]{6}") # must be len-6 hex
-
- stringr::str_match_all(text, "\\$(.+)\\s*:\\s*(#[0-9a-fA-F]{6});") %>%
- purrr::discard(~ length(.) < 1) %>%
- purrr::map_dfr(~ tibble(name = .[, 2], color = .[, 3])) %>%
- distinct(name, color) %>%
- mutate(name = factor(name, unique(name)))
- }
-
-
- show_colors <- function(colors, ...) {
- ggplot(colors) +
- aes(1, 1, fill = color) +
- geom_tile() +
- facet_wrap(~ name + color, ...) +
- scale_fill_identity() +
- theme_void()
- }
|