浏览代码

Add show colors

one
父节点
当前提交
422901969b
共有 1 个文件被更改,包括 22 次插入0 次删除
  1. +22
    -0
      R/show_colors.R

+ 22
- 0
R/show_colors.R 查看文件

@@ -0,0 +1,22 @@
library(tidyverse)

read_colors <- function(file) {
text <- readLines(file, warn = FALSE) %>%
str_subset("#[0-9a-fA-F]{6}") # must be len-6 hex
str_match_all(text, "\\$(.+)\\s*:\\s*(#[0-9a-fA-F]{6});") %>%
discard(~ length(.) < 1) %>%
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()
}

正在加载...
取消
保存