選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

53 行
1.5KB

  1. proc_data <- function(x, .id = "x") {
  2. colors <- scales::brewer_pal(type = "qual", "Set1")(max(x$id))
  3. x %>%
  4. mutate(.y = -row_number()) %>%
  5. tidyr::gather("label", "value", -.y) %>%
  6. mutate(value = as.character(value)) %>%
  7. group_by(.y) %>%
  8. mutate(
  9. .x = 1:n(),
  10. .id = .id,
  11. color = ifelse(label == "id", value, max(x$id) + 1),
  12. color = colors[as.integer(color)],
  13. color = ifelse(is.na(color), "#d0d0d0", color),
  14. color = ifelse(is.na(value), "#ffffff", color)
  15. )
  16. }
  17. plot_data <- function(x, title = "") {
  18. ggplot(x) +
  19. aes(.x, .y, fill = color, label = value) +
  20. geom_tile(color = "white", size = 3) +
  21. geom_text(aes(x = .x), hjust = 0.5, size = 12, family = "Fira Sans", color = "white") +
  22. scale_fill_identity() +
  23. coord_equal() +
  24. ggtitle(title) +
  25. theme_void() +
  26. theme(plot.title = element_text(family = "Fira Mono", hjust = 0.5, size = 24)) +
  27. guides(fill = FALSE)
  28. }
  29. animate_plot <- function(x) {
  30. x +
  31. transition_states(frame, transition_length = 2, state_length = 1) +
  32. enter_fade() +
  33. exit_fade() +
  34. ease_aes("sine-in-out")
  35. }
  36. save_static_plot <- function(g, filename, formats = c("png", "svg")) {
  37. filenames <- formats %>%
  38. purrr::set_names() %>%
  39. purrr::map_chr(static_plot_filename, x = filename) %>%
  40. purrr::iwalk(
  41. ~ ggsave(filename = .x, plot = g, dev = .y)
  42. )
  43. }
  44. static_plot_filename <- function(x, ext) {
  45. here::here("images", "static", ext, paste0(x, ".", ext))
  46. }
  47. options(tidy_verb_anim.functions_loaded = TRUE)