You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 satır
2.5KB

  1. library(tidyAnimatedVerbs)
  2. library(here)
  3. check_and_create <- function(ff) {
  4. if (!dir.exists(ff)) dir.create(ff, recursive = T)
  5. }
  6. x <- data_frame(
  7. id = 1:3,
  8. x = paste0("x", 1:3)
  9. )
  10. y <- data_frame(
  11. id = (1:4)[-3],
  12. y = paste0("y", (1:4)[-3])
  13. )
  14. check_and_create(here("images", "static", "png"))
  15. joins <- c(full_join = animate_full_join,
  16. inner_join = animate_inner_join,
  17. left_join = animate_left_join,
  18. right_join = animate_right_join,
  19. semi_join = animate_semi_join)
  20. a <- sapply(1:length(joins), function(i) {
  21. nam <- names(joins)[i]
  22. nam <- str_replace(nam, "_", "-")
  23. cat(nam, "\n")
  24. width <- 7
  25. height <- 7
  26. gif_ <- joins[[i]](x, y, by = "id")
  27. first_ <- joins[[i]](x, y, by = "id", export = "first")
  28. last_ <- joins[[i]](x, y, by = "id", export = "last")
  29. save_animation(gif_, here("images", paste0(nam, ".gif")))
  30. ggsave(here("images", "static", "png", paste0(nam, "-first.png")), first_,
  31. height = height, width = width)
  32. ggsave(here("images", "static", "svg", paste0(nam, "-first.svg")), first_,
  33. height = height, width = width)
  34. ggsave(here("images", "static", "png", paste0(nam, "-last.png")), last_,
  35. height = height, width = width)
  36. ggsave(here("images", "static", "svg", paste0(nam, "-last.svg")), last_,
  37. height = height, width = width)
  38. })
  39. # instr_extra <- instr %>% slice(c(1, 1:n()))
  40. # animate_left_join(singer, instr_extra, by = c("name", "band")) # <- NOT WORKING
  41. x <- tibble::tribble(
  42. ~x, ~y,
  43. "1", "a",
  44. "1", "b",
  45. "2", "a"
  46. )
  47. y <- tibble::tribble(
  48. ~x, ~y,
  49. "1", "a",
  50. "2", "b"
  51. )
  52. sets <- c(union = animate_union,
  53. union_all = animate_union_all,
  54. intersect = animate_intersect,
  55. setdiff = animate_setdiff)
  56. a <- sapply(1:length(sets), function(i) {
  57. nam <- names(sets)[i]
  58. nam <- str_replace(nam, "_", "-")
  59. cat(nam, "\n")
  60. width <- 7
  61. height <- 7
  62. gif_ <- sets[[i]](x, y)
  63. first_ <- sets[[i]](x, y, export = "first")
  64. last_ <- sets[[i]](x, y, export = "last")
  65. save_animation(gif_, here("images", paste0(nam, ".gif")))
  66. ggsave(here("images", "static", "png", paste0(nam, "-first.png")), first_,
  67. height = height, width = width)
  68. ggsave(here("images", "static", "svg", paste0(nam, "-first.svg")), first_,
  69. height = height, width = width)
  70. ggsave(here("images", "static", "png", paste0(nam, "-last.png")), last_,
  71. height = height, width = width)
  72. ggsave(here("images", "static", "svg", paste0(nam, "-last.svg")), last_,
  73. height = height, width = width)
  74. })