No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

94 líneas
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_right_join)
  20. a <- sapply(1:length(joins), function(i) {
  21. nam <- names(joins)[i]
  22. nam <- str_replace(nam, "_", "-")
  23. width <- 7
  24. height <- 7
  25. gif_ <- joins[[i]](x, y, by = "id")
  26. first_ <- joins[[i]](x, y, by = "id", export = "first")
  27. last_ <- joins[[i]](x, y, by = "id", export = "last")
  28. save_animation(gif_, here("images", paste0(nam, ".gif")))
  29. ggsave(here("images", "static", "png", paste0(nam, "-first.png")), first_,
  30. height = height, width = width)
  31. ggsave(here("images", "static", "svg", paste0(nam, "-first.svg")), first_,
  32. height = height, width = width)
  33. ggsave(here("images", "static", "png", paste0(nam, "-last.png")), last_,
  34. height = height, width = width)
  35. ggsave(here("images", "static", "svg", paste0(nam, "-last.svg")), last_,
  36. height = height, width = width)
  37. })
  38. # instr_extra <- instr %>% slice(c(1, 1:n()))
  39. # animate_left_join(singer, instr_extra, by = c("name", "band")) # <- NOT WORKING
  40. x <- tibble::tribble(
  41. ~x, ~y,
  42. "1", "a",
  43. "1", "b",
  44. "2", "a"
  45. )
  46. y <- tibble::tribble(
  47. ~x, ~y,
  48. "1", "a",
  49. "2", "b"
  50. )
  51. sets <- c(union = animate_union,
  52. union_all = animate_union_all,
  53. intersect = animate_intersect,
  54. setdiff = animate_setdiff)
  55. a <- sapply(1:length(sets), function(i) {
  56. nam <- names(sets)[i]
  57. nam <- str_replace(nam, "_", "-")
  58. width <- 7
  59. height <- 7
  60. gif_ <- sets[[i]](x, y, by = "id")
  61. first_ <- sets[[i]](x, y, by = "id", export = "first")
  62. last_ <- sets[[i]](x, y, by = "id", export = "last")
  63. save_animation(gif_, here("images", paste0(nam, ".gif")))
  64. ggsave(here("images", "static", "png", paste0(nam, "-first.png")), first_,
  65. height = height, width = width)
  66. ggsave(here("images", "static", "svg", paste0(nam, "-first.svg")), first_,
  67. height = height, width = width)
  68. ggsave(here("images", "static", "png", paste0(nam, "-last.png")), last_,
  69. height = height, width = width)
  70. ggsave(here("images", "static", "svg", paste0(nam, "-last.svg")), last_,
  71. height = height, width = width)
  72. })