Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

51 lines
1.1KB

  1. # Animated dplyr set opertaions with gganimate
  2. # * Contributed by Tyler Grant Smith <https://github.com/TylerGrantSmith>
  3. # * and Garrick Aden-Buie <https://www.garrickadenbuie.com>
  4. # * MIT License: https://opensource.org/licenses/MIT
  5. library(tidyverse)
  6. library(gganimate)
  7. if (!getOption("tidy_verb_anim.font_registered", FALSE)) {
  8. source(here::here("R", "01_register-fonts.R"))
  9. }
  10. if (!getOption("tidy_verb_anim.functions_loaded", FALSE)) {
  11. source(here::here("R", "02_functions.R"))
  12. }
  13. if (!dir.exists(here::here("images"))) dir.create(here::here("images"))
  14. # Initialize data processing function ----
  15. proc_data_set <- function(x, .id = "x") {
  16. proc_data(x, .id, colorize_row_id, "before")
  17. }
  18. plot_data_set <- function(x, title = "", xlims = xlim(1.5, 6.5), ylims = ylim(-3.5, -0.5)) {
  19. filter(x, label != "id") %>%
  20. plot_data(title) +
  21. xlims + ylims
  22. }
  23. # Data ----
  24. x <- tibble::tribble(
  25. ~id, ~x, ~y,
  26. 1, "1", "a",
  27. 2, "1", "b",
  28. 3, "2", "a"
  29. )
  30. y <- tibble::tribble(
  31. ~id, ~x, ~y,
  32. 1, "1", "a",
  33. 4, "2", "b"
  34. )
  35. initial_set_dfs <- bind_rows(
  36. proc_data_set(x, "x"),
  37. proc_data_set(y, "y") %>% mutate(.x = .x + 3)
  38. ) %>%
  39. mutate(frame = 1)