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.

83 lines
2.1KB

  1. #' Animates a set operation
  2. #'
  3. #' Functions to visualise the set 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 export the export type, either gif, first or last. The latter two
  9. #' export ggplots of the first/last state of the join
  10. #' @param ... further argument passed to base_plot
  11. #'
  12. #' @return either a gif or a ggplot
  13. #'
  14. #' @seealso \code{\link[dplyr]{setops}}
  15. #'
  16. #' @name animate_set
  17. #' @examples
  18. #' x <- data_frame(
  19. #' id = 1:3,
  20. #' x = paste0("x", 1:3)
  21. #' )
  22. #' y <- data_frame(
  23. #' id = (1:4)[-3],
  24. #' y = paste0("y", (1:4)[-3])
  25. #' )
  26. #'
  27. #' animate_union(x, y, by = "id", export = "first")
  28. #' animate_union(x, y, by = "id", export = "last")
  29. #'
  30. #' # Animate the first or last state of the join
  31. #' animate_union(x, y, export = "first")
  32. #' animate_union(x, y, export = "last")
  33. #'
  34. #' # animate the transition as a gif (default)
  35. #' \donttest{
  36. #' animate_union(x, y, export = "gif")
  37. #' }
  38. #'
  39. #' # different options include
  40. #' \donttest{
  41. #' animate_union(x, y, by = "id")
  42. #' animate_union_all(x, y, by = "id")
  43. #' animate_intersect(x, y, by = "id")
  44. #' animate_setdiff(x, y, by = "id")
  45. #' }
  46. #'
  47. #' # Save the results
  48. #' \dontrun{
  49. #' # to save the ggplot, use
  50. #' un <- animate_union(x, y, by = "id", export = "last")
  51. #' ggsave("union.pdf", un)
  52. #'
  53. #' animate_union(x, y, by = "id", export = "gif")
  54. #' # to save the gif, use
  55. #' un <- animate_union(x, y, by = "id", export = "gif")
  56. #' anim_save(un, "union.gif")
  57. #' }
  58. NULL
  59. #' @rdname animate_set
  60. #' @export
  61. animate_union <- function(x, y, export = "gif", ...) {
  62. animate_set(x, y, type = "union", export = export, ...)
  63. }
  64. #' @rdname animate_set
  65. #' @export
  66. animate_union_all <- function(x, y, export = "gif", ...) {
  67. animate_set(x, y, type = "union_all", export = export, ...)
  68. }
  69. #' @rdname animate_set
  70. #' @export
  71. animate_intersect <- function(x, y, export = "gif", ...) {
  72. animate_set(x, y, type = "intersect", export = export, ...)
  73. }
  74. #' @rdname animate_set
  75. #' @export
  76. animate_setdiff <- function(x, y, export = "gif", ...) {
  77. animate_set(x, y, type = "setdiff", export = export, ...)
  78. }