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.

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