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.

103 lines
2.8KB

  1. #' Animates a join operations
  2. #'
  3. #' Functions to visualise the join operations either static as a ggplot, or
  4. #' dynamic as a gif.
  5. #'
  6. #' @param x the x dataset
  7. #' @param y the y dataset
  8. #' @param by the by arguments for the join
  9. #' @param export the export type, either gif, first or last. The latter two
  10. #' export ggplots of the first/last state of the join
  11. #' @param ... further arguments passed to base_plot
  12. #'
  13. #' @return either a gif or a ggplot
  14. #'
  15. #' @seealso \code{\link[dplyr]{join}}
  16. #'
  17. #' @name animate_join
  18. #' @examples
  19. #' x <- data_frame(
  20. #' id = 1:3,
  21. #' x = paste0("x", 1:3)
  22. #' )
  23. #' y <- data_frame(
  24. #' id = (1:4)[-3],
  25. #' y = paste0("y", (1:4)[-3])
  26. #' )
  27. #'
  28. #' # Animate the first or last state of the join
  29. #' animate_full_join(x, y, by = "id", export = "first")
  30. #' animate_full_join(x, y, by = "id", export = "last")
  31. #'
  32. #' # animate the transition as a gif (default)
  33. #' \donttest{
  34. #' animate_full_join(x, y, by = "id", export = "gif")
  35. #' }
  36. #'
  37. #' # different options include
  38. #' \donttest{
  39. #' animate_full_join(x, y, by = "id")
  40. #' animate_inner_join(x, y, by = "id")
  41. #' animate_left_join(x, y, by = "id")
  42. #' animate_right_join(x, y, by = "id")
  43. #' animate_semi_join(x, y, by = "id")
  44. #' animate_anti_join(x, y, by = "id")
  45. #'
  46. #' # further arguments can be passed to all animate_* functions
  47. #' animate_full_join(
  48. #' x, y, by = "id", export = "last",
  49. #' text_size = 5, title_size = 25,
  50. #' color_header = "black",
  51. #' color_other = "lightblue",
  52. #' color_fun = viridis::viridis
  53. #' )
  54. #' }
  55. #'
  56. #' # Save the results
  57. #' \donttest{
  58. #' # to save the ggplot, use
  59. #' fj <- animate_full_join(x, y, by = "id", export = "last")
  60. #' ggsave("full-join.pdf", fj)
  61. #'
  62. #' # to save the gif, use
  63. #' fj <- animate_full_join(x, y, by = "id", export = "gif")
  64. #' anim_save(fj, "full-join.gif")
  65. #' }
  66. NULL
  67. #' @rdname animate_join
  68. #' @export
  69. animate_full_join <- function(x, y, by, export = "gif", ...) {
  70. animate_join(x, y, by, type = "full_join", export = export, ...)
  71. }
  72. #' @rdname animate_join
  73. #' @export
  74. animate_inner_join <- function(x, y, by, export = "gif", ...) {
  75. animate_join(x, y, by, type = "inner_join", export = export, ...)
  76. }
  77. #' @rdname animate_join
  78. #' @export
  79. animate_left_join <- function(x, y, by, export = "gif", ...) {
  80. animate_join(x, y, by, type = "left_join", export = export, ...)
  81. }
  82. #' @rdname animate_join
  83. #' @export
  84. animate_right_join <- function(x, y, by, export = "gif", ...) {
  85. animate_join(x, y, by, type = "right_join", export = export, ...)
  86. }
  87. #' @rdname animate_join
  88. #' @export
  89. animate_semi_join <- function(x, y, by, export = "gif", ...) {
  90. animate_join(x, y, by, type = "semi_join", export = export, ...)
  91. }
  92. #' @rdname animate_join
  93. #' @export
  94. animate_anti_join <- function(x, y, by, export = "gif", ...) {
  95. animate_join(x, y, by, type = "anti_join", export = export, ...)
  96. }