🍑 Pomological plot theme for ggplot2
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

85 lines
2.9KB

  1. # # load all colors
  2. # x <- readLines("pomological.css")
  3. # x <- stringr::str_extract(x, "#[0-9a-f]{6}")
  4. # x <- x[!is.na(x)]
  5. #
  6. # gg_color_hue <- function(n) {
  7. # hues = seq(15, 375, length = n + 1)
  8. # hcl(h = hues, l = 65, c = 100)[1:n]
  9. # }
  10. #
  11. # col2hsv <- function(x) rgb2hsv(col2rgb(x))
  12. #
  13. #
  14. # dist2ref_color <- function(color, ref_color) {
  15. # stopifnot(length(ref_color) == 1)
  16. # x <- col2hsv(c(color, ref_color)) %>%
  17. # t %>%
  18. # dist %>%
  19. # as.matrix %>%
  20. # {tibble('ref_color' = .[length(color) + 1, 1:length(color)])}
  21. # names(x) <- ref_color
  22. # x
  23. # }
  24. #
  25. # compare_to_ggplot <- function(compare_to_ggplot) {
  26. # pomo_gg <- map_dfr(set_names(compare_to_ggplot), ~ as_tibble(t(col2hsv(.))), .id = "color") %>%
  27. # bind_cols(
  28. # map_dfc(gg_color_hue(set_names(length(compare_to_ggplot))), ~ dist2ref_color(compare_to_ggplot, .))
  29. # ) %>%
  30. # tidyr::gather('ggplot_color', 'dist', -color:-v) %>%
  31. # # group_by(color) %>%
  32. # # do(dist = min(.$dist), ggplot_color = filter(., dist == min(.$dist))$ggplot_color) %>%
  33. # # mutate(dist = map_dbl(dist, ~ .), ggplot_color = map_chr(ggplot_color, ~ .)) %>%
  34. # # ungroup %>%
  35. # mutate(ggplot_color = factor(ggplot_color, gg_color_hue(length(compare_to_ggplot)))) %>%
  36. # arrange(ggplot_color)
  37. # warning(glue::glue("Palette has {length(compare_to_ggplot)} colors"), call. = FALSE)
  38. # ggplot(pomo_gg) +
  39. # aes(x = ggplot_color, y = dist, fill = color, label = color) +
  40. # geom_label(color = 'white')+
  41. # # geom_point(shape = 15, size = 5) +
  42. # scale_fill_identity()
  43. # }
  44. #
  45. # data_frame(
  46. # 'color' = color_options,
  47. # # 'group' = sample(c('pomo', 'logical'), length(color_options), replace = TRUE),
  48. # 'x' = pmap_chr(tidyr::crossing(letters, letters), ~paste0(..1, ..2))[1:length(color_options)],
  49. # 'y' = 1:length(color_options)
  50. # ) %>%
  51. # ggplot() +
  52. # aes(x, y, fill = color) +
  53. # # geom_point(size = 8)+
  54. # geom_col()+
  55. # geom_text(aes(label = color), hjust = -0.1) +
  56. # scale_fill_identity() +
  57. # coord_flip() +
  58. # theme_minimal() +
  59. # #theme_xkcd() +
  60. # theme(
  61. # text = element_text(family = 'gWriting', size = 16),
  62. # plot.background = element_rect(fill = base_colors["paper_light"], color = NA),
  63. # panel.grid = element_line(color = "#efe1c6"),
  64. # axis.text = element_text(color = "#655843", size = 14)
  65. # )
  66. #
  67. # ordered_plot <- function(color_options, dichromat = FALSE) {
  68. # if (dichromat) {
  69. # dichr_type <- sample(c("deutan", "protan", "tritan"), 1)
  70. # message(glue::glue("color blindness: {dichr_type}"))
  71. # color_options <- dichromat::dichromat(color_options, dichr_type)
  72. # }
  73. # data_frame(
  74. # color = color_options,
  75. # x = 1,
  76. # y = 1:length(color_options)
  77. # ) %>%
  78. # ggplot() +
  79. # aes(x, y, fill = color, label = color) +
  80. # geom_tile() +
  81. # geom_label(color = 'white') +
  82. # scale_fill_identity()+
  83. # scale_y_continuous(breaks = 1:length(color_options), labels = 1:length(color_options))+
  84. # theme_minimal()
  85. # }