Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

89 rindas
2.2KB

  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 static_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. #' x = c(1, 1, 2),
  20. #' y = c("a", "b", "a")
  21. #' )
  22. #' y <- data_frame(
  23. #' x = c(1, 2),
  24. #' y = c("a", "b")
  25. #' )
  26. #'
  27. #' # Animate the first or last state of the set
  28. #' animate_union(x, y, export = "first")
  29. #' animate_union(x, y, export = "last")
  30. #'
  31. #' # animate the transition as a gif (default)
  32. #' \donttest{
  33. #' animate_union(x, y, export = "gif")
  34. #' }
  35. #'
  36. #' # different options include
  37. #' \donttest{
  38. #' animate_union(x, y)
  39. #' animate_union_all(x, y)
  40. #' animate_intersect(x, y)
  41. #' animate_setdiff(x, y)
  42. #'
  43. #' # further arguments can be passed to all animate_* functions
  44. #' animate_union(
  45. #' x, y,
  46. #' text_size = 5, title_size = 25,
  47. #' color_header = "black",
  48. #' color_other = "lightblue",
  49. #' color_fun = viridis::viridis
  50. #' )
  51. #' }
  52. #'
  53. #' # Save the results
  54. #' \dontrun{
  55. #' # to save the ggplot, use
  56. #' un <- animate_union(x, y, by = "id", export = "last")
  57. #' ggsave("union.pdf", un)
  58. #'
  59. #' animate_union(x, y, by = "id", export = "gif")
  60. #' # to save the gif, use
  61. #' un <- animate_union(x, y, by = "id", export = "gif")
  62. #' anim_save(un, "union.gif")
  63. #' }
  64. NULL
  65. #' @rdname animate_set
  66. #' @export
  67. animate_union <- function(x, y, export = "gif", ...) {
  68. animate_set(x, y, type = "union", export = export, ...)
  69. }
  70. #' @rdname animate_set
  71. #' @export
  72. animate_union_all <- function(x, y, export = "gif", ...) {
  73. animate_set(x, y, type = "union_all", export = export, ...)
  74. }
  75. #' @rdname animate_set
  76. #' @export
  77. animate_intersect <- function(x, y, export = "gif", ...) {
  78. animate_set(x, y, type = "intersect", export = export, ...)
  79. }
  80. #' @rdname animate_set
  81. #' @export
  82. animate_setdiff <- function(x, y, export = "gif", ...) {
  83. animate_set(x, y, type = "setdiff", export = export, ...)
  84. }