| ^.*\.Rproj$ | |||||
| ^\.Rproj\.user$ |
| Package: tidyAnimatedVerbs | |||||
| Type: Package | |||||
| Title: Animate Tidy Verbs | |||||
| Version: 0.1 | |||||
| Date: 2018-08-19 | |||||
| Author: Name | |||||
| Maintainer: Name <email@email.com> | |||||
| Description: This package allows to visualise the verbs of dplyr and tidyr | |||||
| License: CC0-1.0 | |||||
| Depends: tidyverse, | |||||
| gganimate (>= 0.9.9.9999) | |||||
| RoxygenNote: 6.1.0 | |||||
| Suggests: | |||||
| knitr | |||||
| VignetteBuilder: knitr | |||||
| Encoding: UTF-8 |
| # Generated by roxygen2: do not edit by hand | |||||
| export(animate_anti_join) | |||||
| export(animate_full_join) | |||||
| export(animate_inner_join) | |||||
| export(animate_intersect) | |||||
| export(animate_left_join) | |||||
| export(animate_right_join) | |||||
| export(animate_semi_join) | |||||
| export(animate_setdiff) | |||||
| export(animate_union) | |||||
| export(animate_union_all) | |||||
| export(combine) |
| # Animated dplyr joins with gganimate | |||||
| # * Garrick Aden-Buie | |||||
| # * garrickadenbuie.com | |||||
| # * MIT License: https://opensource.org/licenses/MIT | |||||
| library(tidyverse) | |||||
| library(gganimate) | |||||
| if (!getOption("tidy_verb_anim.font_registered", FALSE)) { | |||||
| source(here::here("R", "01_register-fonts.R")) | |||||
| } | |||||
| if (!getOption("tidy_verb_anim.functions_loaded", FALSE)) { | |||||
| source(here::here("R", "02_functions.R")) | |||||
| } | |||||
| source(here::here("R", "03_check-folders.R")) | |||||
| plot_data_join <- function(x, title = "", xlims = xlim(0.5, 5.5), ylims = ylim(-3.5, -0.5)) { | |||||
| plot_data(x, title) + | |||||
| xlims + ylims | |||||
| } | |||||
| # Data ---- | |||||
| x <- data_frame( | |||||
| id = 1:3, | |||||
| x = paste0("x", 1:3) | |||||
| ) | |||||
| y <- data_frame( | |||||
| id = (1:4)[-3], | |||||
| y = paste0("y", (1:4)[-3]) | |||||
| ) | |||||
| initial_join_dfs <- proc_data(x, "x") %>% | |||||
| bind_rows(mutate(proc_data(y, "y"), .x = .x + 3)) %>% | |||||
| mutate(frame = 1) |
| # Animated dplyr set opertaions with gganimate | |||||
| # * Contributed by Tyler Grant Smith <https://github.com/TylerGrantSmith> | |||||
| # * and Garrick Aden-Buie <https://www.garrickadenbuie.com> | |||||
| # * MIT License: https://opensource.org/licenses/MIT | |||||
| library(tidyverse) | |||||
| library(gganimate) | |||||
| if (!getOption("tidy_verb_anim.font_registered", FALSE)) { | |||||
| source(here::here("R", "01_register-fonts.R")) | |||||
| } | |||||
| if (!getOption("tidy_verb_anim.functions_loaded", FALSE)) { | |||||
| source(here::here("R", "02_functions.R")) | |||||
| } | |||||
| source(here::here("R", "03_check-folders.R")) | |||||
| # Initialize data processing function ---- | |||||
| proc_data_set <- function(x, .id = "x") { | |||||
| proc_data(x, .id, colorize_row_id, "before") | |||||
| } | |||||
| plot_data_set <- function(x, title = "", xlims = xlim(1.5, 6.5), ylims = ylim(-3.5, -0.5)) { | |||||
| filter(x, label != "id") %>% | |||||
| plot_data(title) + | |||||
| xlims + ylims | |||||
| } | |||||
| # Data ---- | |||||
| x <- tibble::tribble( | |||||
| ~id, ~x, ~y, | |||||
| 1, "1", "a", | |||||
| 2, "1", "b", | |||||
| 3, "2", "a" | |||||
| ) | |||||
| y <- tibble::tribble( | |||||
| ~id, ~x, ~y, | |||||
| 1, "1", "a", | |||||
| 4, "2", "b" | |||||
| ) | |||||
| initial_set_dfs <- bind_rows( | |||||
| proc_data_set(x, "x"), | |||||
| proc_data_set(y, "y") %>% mutate(.x = .x + 3) | |||||
| ) %>% | |||||
| mutate(frame = 1) |
| # Note: I used Fira Sans and Mono (downloaded here from Google Fonts). | |||||
| # Feel free to change font names below for desired fonts. | |||||
| sysfonts::font_add_google("Fira Sans") | |||||
| sysfonts::font_add_google("Fira Mono") | |||||
| showtext::showtext_auto() | |||||
| options(tidy_verb_anim.font_registered = TRUE) |
| proc_data <- function(x, .id = "x", color_fun = colorize_keys, color_when = c("after", "before"), ...) { | |||||
| color_when <- match.arg(color_when) | |||||
| n_colors <- max(x$id) | |||||
| if (color_when == "before") x <- color_fun(x, n_colors, ...) | |||||
| x <- x %>% | |||||
| mutate(.y = -row_number()) %>% | |||||
| tidyr::gather("label", "value", setdiff(colnames(x), c(".y", "color"))) %>% | |||||
| mutate(value = as.character(value)) %>% | |||||
| group_by(.y) %>% | |||||
| mutate( | |||||
| .x = 1:n(), | |||||
| .id = .id, | |||||
| .width = 1 | |||||
| ) %>% | |||||
| ungroup(.y) | |||||
| if (color_when == "after") x <- color_fun(x, n_colors, ...) | |||||
| x | |||||
| } | |||||
| colorize_keys <- function(df, n_colors, key_col = "id", color_other = "#d0d0d0", color_missing = "#ffffff") { | |||||
| # Assumes that key_col is integer | |||||
| colors <- scales::brewer_pal(type = "qual", "Set1")(n_colors) | |||||
| mutate( | |||||
| df, | |||||
| color = ifelse(label == key_col, value, n_colors + 1), | |||||
| color = colors[as.integer(color)], | |||||
| color = ifelse(is.na(color), "#d0d0d0", color), | |||||
| color = ifelse(is.na(value), "#ffffff", color) | |||||
| ) | |||||
| } | |||||
| colorize_row_id <- function(df, n_colors, key_col = "id") { | |||||
| # Assumes that key_col is integer | |||||
| colors <- scales::brewer_pal(type = "qual", "Set1")(n_colors) | |||||
| df$color <- colors[df[[key_col]]] | |||||
| df | |||||
| } | |||||
| plot_data <- function(x, title = "") { | |||||
| if (!"alpha" %in% colnames(x)) x$alpha <- 1 | |||||
| if (!".width" %in% colnames(x)) x$`.width` <- 1 | |||||
| ggplot(x) + | |||||
| aes(.x, .y, fill = color, label = value) + | |||||
| geom_tile(aes(width = .width, alpha = alpha), color = "white", size = 3) + | |||||
| geom_text(aes(x = .x), hjust = 0.5, size = 12, family = "Fira Sans", color = "white") + | |||||
| scale_fill_identity() + | |||||
| scale_alpha_identity() + | |||||
| coord_equal() + | |||||
| ggtitle(title) + | |||||
| theme_void() + | |||||
| theme(plot.title = element_text(family = "Fira Mono", hjust = 0.5, size = 24)) + | |||||
| guides(fill = FALSE) | |||||
| } | |||||
| animate_plot <- function(x, transition_length = 2, state_length = 1) { | |||||
| x + | |||||
| transition_states(frame, transition_length, state_length) + | |||||
| enter_fade() + | |||||
| exit_fade() + | |||||
| ease_aes("sine-in-out") | |||||
| } | |||||
| save_static_plot <- function(g, filename, formats = c("png", "svg")) { | |||||
| filenames <- formats %>% | |||||
| purrr::set_names() %>% | |||||
| purrr::map_chr(static_plot_filename, x = filename) %>% | |||||
| purrr::iwalk( | |||||
| ~ ggsave(filename = .x, plot = g, dev = .y) | |||||
| ) | |||||
| } | |||||
| static_plot_filename <- function(x, ext) { | |||||
| here::here("images", "static", ext, paste0(x, ".", ext)) | |||||
| } | |||||
| options(tidy_verb_anim.functions_loaded = TRUE) |
| if (!dir.exists(here::here("images"))) dir.create(here::here("images")) | |||||
| png_path <- here::here("images", "static", "png") | |||||
| svg_path <- here::here("images", "static", "svg") | |||||
| if (!dir.exists(png_path)) dir.create(png_path, recursive = TRUE) | |||||
| if (!dir.exists(svg_path)) dir.create(svg_path, recursive = TRUE) |
| #' Animates a set - wrapper function | |||||
| #' | |||||
| #' @param x left dataset | |||||
| #' @param y right dataset | |||||
| #' @param type type of the set, i.e., intersect, setdiff, etc. | |||||
| #' @param export if the function exports a gif, the first, or last picture | |||||
| #' @param ... further arguments passed to base_plot | |||||
| #' | |||||
| #' @return either a gif or a ggplot | |||||
| #' | |||||
| #' @examples | |||||
| #' NULL | |||||
| animate_set <- function(x, y, type, export = "gif", ...) { | |||||
| if (!all(names(x) %in% names(y)) && ncol(x) == ncol(y)) | |||||
| stop("x and y must have the same variables/column-names") | |||||
| if (!type %in% c("union", "union_all", "intersect", "setdiff")) | |||||
| stop("type has to be a dplyr-set operation") | |||||
| if (!export %in% c("gif", "first", "last")) | |||||
| stop("export must be either gif, first, or last") | |||||
| title <- sprintf(paste0(type, "(%s, %s)"), | |||||
| deparse(substitute(x)), | |||||
| deparse(substitute(y))) | |||||
| ll <- preprocess_data(x, y, by = names(x)) | |||||
| step0 <- bind_rows(ll$x, ll$y) %>% mutate(.frame = 0, .alpha = 1) | |||||
| step1 <- tidyAnimatedVerbs:::combine(ll$x, ll$y, type) %>% mutate(.frame = 1) | |||||
| all <- bind_rows(step0, step1) | |||||
| if (export == "gif") { | |||||
| animate_plot(all, title, ...) %>% animate() | |||||
| } else if (export == "first") { | |||||
| base_plot(step0, title, ...) | |||||
| } else if (export == "last") { | |||||
| base_plot(step1, title, ...) | |||||
| } | |||||
| } | |||||
| #' Animates a join - wrapper function | |||||
| #' | |||||
| #' @param x left dataset | |||||
| #' @param y right dataset | |||||
| #' @param by by arguments for the join | |||||
| #' @param type type of the join, i.e., left_join, right_join, etc. | |||||
| #' @param export if the function exports a gif, the first, or last picture | |||||
| #' @param ... further arguments passed to base_plot | |||||
| #' | |||||
| #' @return either a gif or a ggplot | |||||
| #' | |||||
| #' @examples | |||||
| #' NULL | |||||
| animate_join <- function(x, y, by, type, export = "gif", ...) { | |||||
| if (!type %in% c("full_join", "inner_join", "left_join", "right_join", | |||||
| "semi_join", "anti_join")) | |||||
| stop("type has to be a dplyr-join") | |||||
| if (!export %in% c("gif", "first", "last")) | |||||
| stop("export must be either gif, first, or last") | |||||
| title <- sprintf(paste0(type, "(%s, %s, by = c(\"%s\"))"), | |||||
| deparse(substitute(x)), | |||||
| deparse(substitute(y)), | |||||
| paste(by, collapse = "\", \"")) | |||||
| ll <- preprocess_data(x, y, by) | |||||
| step0 <- bind_rows(ll$x, ll$y) %>% mutate(.frame = 0, .alpha = 1) | |||||
| step1 <- tidyAnimatedVerbs:::combine(ll$x, ll$y, type) %>% mutate(.frame = 1) | |||||
| all <- bind_rows(step0, step1) | |||||
| if (export == "gif") { | |||||
| animate_plot(all, title, ...) %>% animate() | |||||
| } else if (export == "first") { | |||||
| base_plot(step0, title, ...) | |||||
| } else if (export == "last") { | |||||
| base_plot(step1, title, ...) | |||||
| } | |||||
| } | |||||
| #' Animates a full join | |||||
| #' | |||||
| #' @param x the x dataset | |||||
| #' @param y the y dataset | |||||
| #' @param by the by arguments for the join | |||||
| #' @param export the export type, either gif, first or last. The latter two | |||||
| #' export ggplots of the first/last state of the join | |||||
| #' @param ... further arguments passed to base_plot | |||||
| #' | |||||
| #' @return either a gif or a ggplot | |||||
| #' @export | |||||
| #' | |||||
| #' @examples | |||||
| #' x <- data_frame( | |||||
| #' id = 1:3, | |||||
| #' x = paste0("x", 1:3) | |||||
| #' ) | |||||
| #' y <- data_frame( | |||||
| #' id = (1:4)[-3], | |||||
| #' y = paste0("y", (1:4)[-3]) | |||||
| #' ) | |||||
| #' | |||||
| #' animate_full_join(x, y, by = "id", export = "first") | |||||
| #' animate_full_join(x, y, by = "id", export = "last") | |||||
| #' | |||||
| #' \dontrun{ | |||||
| #' # to save the ggplot, use | |||||
| #' fj <- animate_full_join(x, y, by = "id", export = "last") | |||||
| #' ggsave("full-join.pdf", fj) | |||||
| #' | |||||
| #' animate_full_join(x, y, by = "id", export = "gif") | |||||
| #' # to save the gif, use | |||||
| #' fj <- animate_full_join(x, y, by = "id", export = "gif") | |||||
| #' anim_save(fj, "full-join.gif") | |||||
| #' } | |||||
| #' | |||||
| animate_full_join <- function(x, y, by, export = "gif", ...) { | |||||
| animate_join(x, y, by, type = "full_join", export = export, ...) | |||||
| } | |||||
| #' Animates an inner join | |||||
| #' | |||||
| #' @inheritParams animate_full_join | |||||
| #' | |||||
| #' @return either a gif or a ggplot | |||||
| #' @export | |||||
| #' | |||||
| #' @examples | |||||
| #' x <- data_frame( | |||||
| #' id = 1:3, | |||||
| #' x = paste0("x", 1:3) | |||||
| #' ) | |||||
| #' y <- data_frame( | |||||
| #' id = (1:4)[-3], | |||||
| #' y = paste0("y", (1:4)[-3]) | |||||
| #' ) | |||||
| #' | |||||
| #' animate_inner_join(x, y, by = "id", export = "first") | |||||
| #' animate_inner_join(x, y, by = "id", export = "last") | |||||
| #' | |||||
| #' \dontrun{ | |||||
| #' # to save the ggplot, use | |||||
| #' ij <- animate_inner_join(x, y, by = "id", export = "last") | |||||
| #' ggsave("inner-join.pdf", ij) | |||||
| #' | |||||
| #' animate_inner_join(x, y, by = "id", export = "gif") | |||||
| #' # to save the gif, use | |||||
| #' ij <- animate_inner_join(x, y, by = "id", export = "gif") | |||||
| #' anim_save(ij, "inner-join.gif") | |||||
| #' } | |||||
| #' | |||||
| animate_inner_join <- function(x, y, by, export = "gif", ...) { | |||||
| animate_join(x, y, by, type = "inner_join", export = export, ...) | |||||
| } | |||||
| #' Animates a left join | |||||
| #' | |||||
| #' @inheritParams animate_full_join | |||||
| #' | |||||
| #' @return either a gif or a ggplot | |||||
| #' @export | |||||
| #' | |||||
| #' @examples | |||||
| #' x <- data_frame( | |||||
| #' id = 1:3, | |||||
| #' x = paste0("x", 1:3) | |||||
| #' ) | |||||
| #' y <- data_frame( | |||||
| #' id = (1:4)[-3], | |||||
| #' y = paste0("y", (1:4)[-3]) | |||||
| #' ) | |||||
| #' | |||||
| #' animate_left_join(x, y, by = "id", export = "first") | |||||
| #' animate_left_join(x, y, by = "id", export = "last") | |||||
| #' | |||||
| #' \dontrun{ | |||||
| #' # to save the ggplot, use | |||||
| #' lj <- animate_left_join(x, y, by = "id", export = "last") | |||||
| #' ggsave("left-join.pdf", lj) | |||||
| #' | |||||
| #' animate_left_join(x, y, by = "id", export = "gif") | |||||
| #' # to save the gif, use | |||||
| #' lj <- animate_left_join(x, y, by = "id", export = "gif") | |||||
| #' anim_save(lj, "left-join.gif") | |||||
| #' } | |||||
| #' | |||||
| animate_left_join <- function(x, y, by, export = "gif", ...) { | |||||
| animate_join(x, y, by, type = "left_join", export = export, ...) | |||||
| } | |||||
| #' Animates a right join | |||||
| #' | |||||
| #' @inheritParams animate_full_join | |||||
| #' | |||||
| #' @return either a gif or a ggplot | |||||
| #' @export | |||||
| #' | |||||
| #' @examples | |||||
| #' x <- data_frame( | |||||
| #' id = 1:3, | |||||
| #' x = paste0("x", 1:3) | |||||
| #' ) | |||||
| #' y <- data_frame( | |||||
| #' id = (1:4)[-3], | |||||
| #' y = paste0("y", (1:4)[-3]) | |||||
| #' ) | |||||
| #' | |||||
| #' animate_right_join(x, y, by = "id", export = "first") | |||||
| #' animate_right_join(x, y, by = "id", export = "last") | |||||
| #' | |||||
| #' \dontrun{ | |||||
| #' # to save the ggplot, use | |||||
| #' rj <- animate_right_join(x, y, by = "id", export = "last") | |||||
| #' ggsave("right-join.pdf", rj) | |||||
| #' | |||||
| #' animate_right_join(x, y, by = "id", export = "gif") | |||||
| #' # to save the gif, use | |||||
| #' rj <- animate_right_join(x, y, by = "id", export = "gif") | |||||
| #' anim_save(rj, "right-join.gif") | |||||
| #' } | |||||
| #' | |||||
| animate_right_join <- function(x, y, by, export = "gif", ...) { | |||||
| animate_join(x, y, by, type = "right_join", export = export, ...) | |||||
| } | |||||
| #' Animates a semi join | |||||
| #' | |||||
| #' @inheritParams animate_full_join | |||||
| #' | |||||
| #' @return either a gif or a ggplot | |||||
| #' @export | |||||
| #' | |||||
| #' @examples | |||||
| #' x <- data_frame( | |||||
| #' id = 1:3, | |||||
| #' x = paste0("x", 1:3) | |||||
| #' ) | |||||
| #' y <- data_frame( | |||||
| #' id = (1:4)[-3], | |||||
| #' y = paste0("y", (1:4)[-3]) | |||||
| #' ) | |||||
| #' | |||||
| #' animate_semi_join(x, y, by = "id", export = "first") | |||||
| #' animate_semi_join(x, y, by = "id", export = "last") | |||||
| #' | |||||
| #' \dontrun{ | |||||
| #' # to save the ggplot, use | |||||
| #' sj <- animate_semi_join(x, y, by = "id", export = "last") | |||||
| #' ggsave("semi-join.pdf", sj) | |||||
| #' | |||||
| #' animate_semi_join(x, y, by = "id", export = "gif") | |||||
| #' # to save the gif, use | |||||
| #' sj <- animate_semi_join(x, y, by = "id", export = "gif") | |||||
| #' anim_save(sj, "semi-join.gif") | |||||
| #' } | |||||
| #' | |||||
| animate_semi_join <- function(x, y, by, export = "gif", ...) { | |||||
| animate_join(x, y, by, type = "semi_join", export = export, ...) | |||||
| } | |||||
| #' Animates an anti join | |||||
| #' | |||||
| #' @inheritParams animate_full_join | |||||
| #' | |||||
| #' @return either a gif or a ggplot | |||||
| #' @export | |||||
| #' | |||||
| #' @examples | |||||
| #' x <- data_frame( | |||||
| #' id = 1:3, | |||||
| #' x = paste0("x", 1:3) | |||||
| #' ) | |||||
| #' y <- data_frame( | |||||
| #' id = (1:4)[-3], | |||||
| #' y = paste0("y", (1:4)[-3]) | |||||
| #' ) | |||||
| #' | |||||
| #' animate_anti_join(x, y, by = "id", export = "first") | |||||
| #' animate_anti_join(x, y, by = "id", export = "last") | |||||
| #' | |||||
| #' \dontrun{ | |||||
| #' # to save the ggplot, use | |||||
| #' aj <- animate_anti_join(x, y, by = "id", export = "last") | |||||
| #' ggsave("anti-join.pdf", aj) | |||||
| #' | |||||
| #' animate_anti_join(x, y, by = "id", export = "gif") | |||||
| #' # to save the gif, use | |||||
| #' aj <- animate_anti_join(x, y, by = "id", export = "gif") | |||||
| #' anim_save(aj, "anti-join.gif") | |||||
| #' } | |||||
| #' | |||||
| animate_anti_join <- function(x, y, by, export = "gif", ...) { | |||||
| animate_join(x, y, by, type = "anti_join", export = export, ...) | |||||
| } |
| #' Animates a union set | |||||
| #' | |||||
| #' @param x the x dataset | |||||
| #' @param y the y dataset | |||||
| #' @param export the export type, either gif, first or last. The latter two | |||||
| #' export ggplots of the first/last state of the join | |||||
| #' @param ... further argument passed to base_plot | |||||
| #' | |||||
| #' @return either a gif or a ggplot | |||||
| #' @export | |||||
| #' | |||||
| #' @examples | |||||
| #' x <- data_frame( | |||||
| #' id = 1:3, | |||||
| #' x = paste0("x", 1:3) | |||||
| #' ) | |||||
| #' y <- data_frame( | |||||
| #' id = (1:4)[-3], | |||||
| #' y = paste0("y", (1:4)[-3]) | |||||
| #' ) | |||||
| #' | |||||
| #' animate_union(x, y, by = "id", export = "first") | |||||
| #' animate_union(x, y, by = "id", export = "last") | |||||
| #' | |||||
| #' \dontrun{ | |||||
| #' # to save the ggplot, use | |||||
| #' un <- animate_union(x, y, by = "id", export = "last") | |||||
| #' ggsave("union.pdf", un) | |||||
| #' | |||||
| #' animate_union(x, y, by = "id", export = "gif") | |||||
| #' # to save the gif, use | |||||
| #' un <- animate_union(x, y, by = "id", export = "gif") | |||||
| #' anim_save(un, "union.gif") | |||||
| #' } | |||||
| #' | |||||
| animate_union <- function(x, y, export = "gif", ...) { | |||||
| animate_set(x, y, type = "union", export = export, ...) | |||||
| } | |||||
| #' Animates a union-all set | |||||
| #' | |||||
| #' @inheritParams animate_union | |||||
| #' | |||||
| #' @return either a gif or a ggplot | |||||
| #' @export | |||||
| #' | |||||
| #' @examples | |||||
| #' x <- data_frame( | |||||
| #' id = 1:3, | |||||
| #' x = paste0("x", 1:3) | |||||
| #' ) | |||||
| #' y <- data_frame( | |||||
| #' id = (1:4)[-3], | |||||
| #' y = paste0("y", (1:4)[-3]) | |||||
| #' ) | |||||
| #' | |||||
| #' animate_union_all(x, y, by = "id", export = "first") | |||||
| #' animate_union_all(x, y, by = "id", export = "last") | |||||
| #' | |||||
| #' \dontrun{ | |||||
| #' # to save the ggplot, use | |||||
| #' un <- animate_union_all(x, y, by = "id", export = "last") | |||||
| #' ggsave("union-all.pdf", un) | |||||
| #' | |||||
| #' animate_union_all(x, y, by = "id", export = "gif") | |||||
| #' # to save the gif, use | |||||
| #' un <- animate_union_all(x, y, by = "id", export = "gif") | |||||
| #' anim_save(un, "union-all.gif") | |||||
| #' } | |||||
| #' | |||||
| animate_union_all <- function(x, y, export = "gif", ...) { | |||||
| animate_set(x, y, type = "union_all", export = export, ...) | |||||
| } | |||||
| #' Animates an intersect set | |||||
| #' | |||||
| #' @inheritParams animate_union | |||||
| #' | |||||
| #' @return either a gif or a ggplot | |||||
| #' @export | |||||
| #' | |||||
| #' @examples | |||||
| #' x <- data_frame( | |||||
| #' id = 1:3, | |||||
| #' x = paste0("x", 1:3) | |||||
| #' ) | |||||
| #' y <- data_frame( | |||||
| #' id = (1:4)[-3], | |||||
| #' y = paste0("y", (1:4)[-3]) | |||||
| #' ) | |||||
| #' | |||||
| #' animate_intersect(x, y, by = "id", export = "first") | |||||
| #' animate_intersect(x, y, by = "id", export = "last") | |||||
| #' | |||||
| #' \dontrun{ | |||||
| #' # to save the ggplot, use | |||||
| #' ints <- animate_intersect(x, y, by = "id", export = "last") | |||||
| #' ggsave("intersect.pdf", ints) | |||||
| #' | |||||
| #' animate_intersect(x, y, by = "id", export = "gif") | |||||
| #' # to save the gif, use | |||||
| #' ints <- animate_union_all(x, y, by = "id", export = "gif") | |||||
| #' anim_save(ints, "intersect.gif") | |||||
| #' } | |||||
| #' | |||||
| animate_intersect <- function(x, y, export = "gif", ...) { | |||||
| animate_set(x, y, type = "intersect", export = export, ...) | |||||
| } | |||||
| #' Animates a setdiff set | |||||
| #' | |||||
| #' @inheritParams animate_union | |||||
| #' | |||||
| #' @return either a gif or a ggplot | |||||
| #' @export | |||||
| #' | |||||
| #' @examples | |||||
| #' x <- data_frame( | |||||
| #' id = 1:3, | |||||
| #' x = paste0("x", 1:3) | |||||
| #' ) | |||||
| #' y <- data_frame( | |||||
| #' id = (1:4)[-3], | |||||
| #' y = paste0("y", (1:4)[-3]) | |||||
| #' ) | |||||
| #' | |||||
| #' animate_setdiff(x, y, by = "id", export = "first") | |||||
| #' animate_setdiff(x, y, by = "id", export = "last") | |||||
| #' | |||||
| #' \dontrun{ | |||||
| #' # to save the ggplot, use | |||||
| #' setd <- animate_setdiff(x, y, by = "id", export = "last") | |||||
| #' ggsave("setdiff.pdf", setd) | |||||
| #' | |||||
| #' animate_setdiff(x, y, by = "id", export = "gif") | |||||
| #' # to save the gif, use | |||||
| #' setd <- animate_union_all(x, y, by = "id", export = "gif") | |||||
| #' anim_save(setd, "setdiff.gif") | |||||
| #' } | |||||
| #' | |||||
| animate_setdiff <- function(x, y, export = "gif", ...) { | |||||
| animate_set(x, y, type = "setdiff", export = export, ...) | |||||
| } |
| source(here::here("R/00_base_join.R")) | |||||
| initial_join_dfs <- initial_join_dfs %>% | |||||
| arrange(.x, .y) %>% | |||||
| mutate(.obj = row_number(), .obj = .obj + 90 * as.integer(.id == "y")) | |||||
| aj_step2 <- initial_join_dfs %>% | |||||
| filter(.id == "x" | value %in% paste(1:2)) %>% | |||||
| mutate(frame = 2, | |||||
| .x = ifelse(.id == "y", 2.5, .x + 1.5), | |||||
| alpha = case_when( | |||||
| .x > 3 && .id == "x" ~ 0.5, | |||||
| .y > -2.5 ~ 0.25, | |||||
| TRUE ~ 1 | |||||
| )) | |||||
| aj_step3 <- aj_step2 %>% | |||||
| filter(alpha == 1) %>% | |||||
| mutate(frame = 3) | |||||
| aj_step4 <- aj_step2 %>% | |||||
| filter(alpha == 1) %>% | |||||
| mutate(frame = 4, .y = -1) | |||||
| aj <- bind_rows( | |||||
| initial_join_dfs, | |||||
| aj_step2, | |||||
| aj_step3, | |||||
| aj_step4 | |||||
| ) %>% | |||||
| mutate( | |||||
| alpha = ifelse(is.na(alpha), 1, alpha), | |||||
| .obj = ifelse(value == 4, 0, .obj) | |||||
| ) %>% | |||||
| arrange(.obj, frame) %>% | |||||
| plot_data("anti_join(x, y)") %>% | |||||
| animate_plot(transition_length = c(2, 1, 2), | |||||
| state_length = c(1, 0, 0, 1)) | |||||
| aj <- animate(aj) | |||||
| anim_save(here::here("images", "anti-join.gif"), aj) | |||||
| aj_g <- anti_join(x, y, by = "id") %>% | |||||
| proc_data() %>% | |||||
| mutate(.x = .x + 1.5) %>% | |||||
| plot_data_join("anti_join(x, y)") | |||||
| save_static_plot(aj_g, "anti-join") |
| #' Combines two processed datasets and combines them for a given method | |||||
| #' | |||||
| #' @param lhs the left-hand side dataset | |||||
| #' @param rhs the righ-hand side dataset | |||||
| #' @param type a string of the desired combination method, allowed are all dplyr | |||||
| #' joins or sets | |||||
| #' | |||||
| #' @return processed dataset of the combined values | |||||
| #' @export | |||||
| #' | |||||
| #' @examples | |||||
| #' NULL | |||||
| combine <- function(lhs, rhs, type) { | |||||
| all_ids <- bind_rows(lhs, rhs) %>% distinct(.id) | |||||
| all <- bind_rows(lhs, rhs) | |||||
| x_cols <- lhs %>% distinct(col) | |||||
| y_cols <- rhs %>% distinct(col) | |||||
| x_ids <- lhs %>% distinct(.id) | |||||
| y_ids <- rhs %>% distinct(.id) | |||||
| if (type == "full_join") { | |||||
| col_combiner <- dplyr::full_join | |||||
| row_combiner <- dplyr::full_join | |||||
| } else if (type == "inner_join") { | |||||
| col_combiner <- dplyr::inner_join | |||||
| row_combiner <- dplyr::inner_join | |||||
| } else if (type == "left_join") { | |||||
| col_combiner <- dplyr::full_join | |||||
| row_combiner <- dplyr::left_join | |||||
| } else if (type == "right_join") { | |||||
| col_combiner <- dplyr::full_join | |||||
| row_combiner <- dplyr::right_join | |||||
| } else if (type == "semi_join") { | |||||
| col_combiner <- dplyr::semi_join | |||||
| row_combiner <- dplyr::semi_join | |||||
| } else if (type == "anti_join") { | |||||
| col_combiner <- dplyr::semi_join | |||||
| row_combiner <- dplyr::anti_join | |||||
| } else if (type == "union") { | |||||
| col_combiner <- dplyr::full_join | |||||
| row_combiner <- dplyr::union | |||||
| } else if (type == "union_all") { | |||||
| col_combiner <- dplyr::full_join | |||||
| row_combiner <- dplyr::union_all | |||||
| x_ids <- lhs %>% distinct(.id = .id_long) | |||||
| y_ids <- rhs %>% distinct(.id = .id_long) | |||||
| all <- all %>% rename(id_old = .id, .id = .id_long) | |||||
| # all <- all %>% rename(.id = .id_long) | |||||
| } else if (type == "intersect") { | |||||
| col_combiner <- dplyr::full_join | |||||
| row_combiner <- dplyr::intersect | |||||
| } else if (type == "setdiff") { | |||||
| col_combiner <- dplyr::full_join | |||||
| row_combiner <- dplyr::anti_join | |||||
| } else { | |||||
| stop("Unknown func") | |||||
| } | |||||
| take_cols <- col_combiner(x_cols, y_cols, by = "col") | |||||
| take_ids <- row_combiner(x_ids, y_ids, by = ".id") | |||||
| # make sure .header is always the first | |||||
| id_number <- which(str_detect(take_ids$.id, "^.header")) | |||||
| if (length(id_number) != 0) | |||||
| take_ids <- take_ids[c(id_number, (1:nrow(take_ids))[-id_number]), ] | |||||
| if (!any(str_detect(take_ids$.id, "^.header"))) | |||||
| take_ids <- bind_rows(data_frame(.id = ".header"), take_ids) | |||||
| take <- tidyr::crossing(take_ids, take_cols) | |||||
| mid <- (2 + length(unique(lhs$col)) + length(unique(rhs$col))) / 2 | |||||
| xvals <- 1:nrow(take_cols) | |||||
| xvals <- xvals - mean(xvals) + mid | |||||
| names(xvals) <- take_cols %>% pull(col) | |||||
| n_non_header <- sum(str_detect(take_ids$.id, "^[^\\.header]")) | |||||
| yvals <- cumsum(ifelse(str_detect(take_ids$.id, "^\\.header"), 0, -1)) | |||||
| names(yvals) <- take_ids %>% pull(.id) | |||||
| take_vals <- semi_join(all, take, by = c(".id", "col")) %>% | |||||
| mutate(.alpha = 1, | |||||
| .x = xvals[col], | |||||
| .y = yvals[.id]) | |||||
| if (type == "union_all") { | |||||
| take_vals <- take_vals %>% rename(.id_long = .id, .id = id_old) | |||||
| } | |||||
| res <- bind_rows( | |||||
| # take, | |||||
| take_vals, | |||||
| # fade in place: | |||||
| all %>% filter(!.id %in% take_ids$.id) %>% mutate(.alpha = 0), | |||||
| # moving fade or fade in place as well: | |||||
| all %>% filter(.id %in% take_ids$.id & !col %in% take_cols$col) %>% | |||||
| mutate(.alpha = 0) | |||||
| ) | |||||
| return(res) | |||||
| } |
| source(here::here("R/00_base_join.R")) | |||||
| fj_joined_df <- full_join(x, y, "id") %>% | |||||
| proc_data("x") %>% | |||||
| mutate(.id = ifelse(value %in% c("4", "y4"), "y", .id)) %>% | |||||
| mutate(frame = 2, .x = .x + 1) | |||||
| fj_extra_blocks <- inner_join(x, y, "id") %>% | |||||
| select(id) %>% | |||||
| proc_data("y") %>% | |||||
| mutate(frame = 2, .x = .x + 1) | |||||
| fj <- initial_join_dfs %>% | |||||
| bind_rows(fj_joined_df, fj_extra_blocks) %>% | |||||
| plot_data("full_join(x, y)") + | |||||
| transition_states(frame, transition_length = 2, state_length = 1) + | |||||
| enter_appear() + | |||||
| exit_disappear(early = TRUE) + | |||||
| ease_aes("sine-in-out") | |||||
| fj <- animate(fj) | |||||
| anim_save(here::here("images", "full-join.gif"), fj) | |||||
| fj_g <- full_join(x, y, "id") %>% | |||||
| proc_data() %>% | |||||
| mutate(.x = .x + 1) %>% | |||||
| plot_data_join("full_join(x, y)", ylims = ylim(-4.5, -0.5)) | |||||
| save_static_plot(fj_g, "full-join") |
| source(here::here("R/00_base_join.R")) | |||||
| ij_joined_df <- inner_join(x, y, "id") | |||||
| ij_joined_df <- bind_rows( | |||||
| proc_data(ij_joined_df, "x"), | |||||
| proc_data(ij_joined_df, "y") | |||||
| ) %>% | |||||
| filter(!(label == "x" & .id == "y") & !(label == "y" & .id == "x")) %>% | |||||
| mutate(frame = 2, .x = .x + 1) | |||||
| ij <- bind_rows( | |||||
| initial_join_dfs, | |||||
| ij_joined_df | |||||
| ) %>% | |||||
| mutate(removed = value %in% c("3", "4", "x3", "y4"), | |||||
| removed = as.integer(removed)) %>% | |||||
| arrange(desc(frame), removed, desc(.id)) %>% | |||||
| plot_data("inner_join(x, y)") %>% | |||||
| animate_plot() | |||||
| ij <- animate(ij) | |||||
| anim_save(here::here("images", "inner-join.gif"), ij) | |||||
| ij_g <- inner_join(x, y, by = "id") %>% | |||||
| proc_data() %>% | |||||
| mutate(.x = .x + 1) %>% | |||||
| plot_data_join("inner_join(x, y)") | |||||
| save_static_plot(ij_g, "inner-join") |
| source(here::here("R/00_base_set.R")) | |||||
| ins_df <- intersect(x,y) | |||||
| ins_step2 <- | |||||
| bind_rows( | |||||
| proc_data_set(ins_df, "x"), | |||||
| proc_data_set(ins_df, "y") | |||||
| ) %>% | |||||
| filter(.y == -1) %>% | |||||
| mutate(frame = 2, .x = .x + 1.5) | |||||
| ins <- | |||||
| initial_set_dfs %>% | |||||
| bind_rows(ins_step2) %>% | |||||
| arrange(desc(frame)) %>% | |||||
| plot_data_set("intersect(x, y)") %>% | |||||
| animate_plot() | |||||
| ins <- animate(ins) | |||||
| anim_save(here::here("images", "intersect.gif"), ins) | |||||
| ins_g <- intersect(x, y) %>% | |||||
| proc_data_set() %>% | |||||
| mutate(.x = .x + 1.5) %>% | |||||
| plot_data_set("intersect(x, y)") | |||||
| save_static_plot(ins_g, "intersect") |
| source(here::here("R/00_base_join.R")) | |||||
| lj_joined_dfs <- left_join(x, y, "id") %>% | |||||
| proc_data("x") %>% | |||||
| mutate(frame = 2, .x = .x + 1) | |||||
| lj_extra_blocks <- inner_join(x, y, "id") %>% | |||||
| select(id) %>% | |||||
| proc_data("y") %>% | |||||
| mutate(frame = 2, .x = .x + 1) | |||||
| lj <- bind_rows( | |||||
| initial_join_dfs, | |||||
| lj_joined_dfs, | |||||
| lj_extra_blocks | |||||
| ) %>% | |||||
| mutate(color = ifelse(is.na(value), "#ffffff", color)) %>% | |||||
| arrange(value) %>% | |||||
| plot_data("left_join(x, y)") %>% | |||||
| animate_plot() | |||||
| lj <- animate(lj) | |||||
| anim_save(here::here("images", "left-join.gif"), lj) | |||||
| lj_g <- plot_data_join(lj_joined_dfs, "left_join(x, y)") | |||||
| save_static_plot(lj_g, "left-join") |
| source(here::here("R/00_base_join.R")) | |||||
| y_extra <- bind_rows(y, data_frame(id = 2, y = "y5")) | |||||
| # I manually linked objects together, it was late and this was easier... | |||||
| anim_df <- tibble::tribble( | |||||
| ~.y, ~label, ~value, ~.x, ~.id, ~color, ~frame, ~obj, | |||||
| -1L, "id", "1", 1, "x", "#E41A1C", 1, 1, | |||||
| -2L, "id", "2", 1, "x", "#377EB8", 1, 2, | |||||
| -2L, "id", "2", 1, "x", "#377EB8", 1, 3, | |||||
| -3L, "id", "3", 1, "x", "#4DAF4A", 1, 4, | |||||
| -1L, "x", "x1", 2, "x", "#d0d0d0", 1, 5, | |||||
| -2L, "x", "x2", 2, "x", "#d0d0d0", 1, 6, | |||||
| -3L, "x", "x3", 2, "x", "#d0d0d0", 1, 8, | |||||
| -2L, "x", "x2", 2, "x", "#d0d0d0", 1, 7, | |||||
| -1L, "id", "1", 4, "y", "#E41A1C", 1, 9, | |||||
| -2L, "id", "2", 4, "y", "#377EB8", 1, 10, | |||||
| -3L, "id", "4", 4, "y", "#984EA3", 1, 99, | |||||
| -4L, "id", "2", 4, "y", "#377EB8", 1, 11, | |||||
| -1L, "y", "y1", 5, "y", "#d0d0d0", 1, 12, | |||||
| -2L, "y", "y2", 5, "y", "#d0d0d0", 1, 13, | |||||
| -3L, "y", "y4", 5, "y", "#d0d0d0", 1, 98, | |||||
| -4L, "y", "y5", 5, "y", "#d0d0d0", 1, 14, | |||||
| -1L, "id", "1", 2, "x", "#E41A1C", 2, 1, | |||||
| -2L, "id", "2", 2, "x", "#377EB8", 2, 2, | |||||
| -3L, "id", "2", 2, "x", "#377EB8", 2, 3, | |||||
| -4L, "id", "3", 2, "x", "#4DAF4A", 2, 4, | |||||
| -1L, "x", "x1", 3, "x", "#d0d0d0", 2, 5, | |||||
| -2L, "x", "x2", 3, "x", "#d0d0d0", 2, 6, | |||||
| -3L, "x", "x2", 3, "x", "#d0d0d0", 2, 7, | |||||
| -4L, "x", "x3", 3, "x", "#d0d0d0", 2, 8, | |||||
| -1L, "y", "y1", 4, "x", "#d0d0d0", 2, 12, | |||||
| -2L, "y", "y2", 4, "x", "#d0d0d0", 2, 13, | |||||
| -3L, "y", "y5", 4, "x", "#d0d0d0", 2, 14, | |||||
| -1L, "id", "1", 2, "y", "#E41A1C", 2, 9, | |||||
| -2L, "id", "2", 2, "y", "#377EB8", 2, 10, | |||||
| -3L, "id", "2", 2, "y", "#377EB8", 2, 11 | |||||
| ) | |||||
| lj_extra <- anim_df %>% | |||||
| arrange(obj, frame) %>% | |||||
| plot_data("left_join(x, y)") %>% | |||||
| animate_plot() | |||||
| lj_extra <- animate(lj_extra) | |||||
| anim_save(here::here("images", "left-join-extra.gif"), lj_extra) | |||||
| ## Save static images | |||||
| df_names <- data_frame( | |||||
| .x = c(1.5, 4.5), .y = 0.25, | |||||
| value = c("x", "y"), | |||||
| size = 12, | |||||
| color = "black" | |||||
| ) | |||||
| g_input <- proc_data(y_extra) %>% | |||||
| mutate(.x = .x + 3) %>% | |||||
| bind_rows(proc_data(x)) %>% | |||||
| plot_data() + | |||||
| geom_text(data = df_names, family = "Fira Mono", size = 24) + | |||||
| annotate("text", label = "↑ duplicate keys in y", x = 4.5, y = -4.75, | |||||
| family = "Fira Sans", color = "grey45") | |||||
| save_static_plot(g_input, "left-join-extra-input") | |||||
| lj_g <- left_join(x, y_extra, by = "id") %>% | |||||
| proc_data() %>% | |||||
| mutate(.x = .x + 1) %>% | |||||
| plot_data_join("left_join(x, y)", ylims = ylim(-4.5, -0.5)) | |||||
| save_static_plot(lj_g, "left-join-extra") |
| #' Animates a plot | |||||
| #' | |||||
| #' @param d a preprocessed dataset | |||||
| #' @param title the plot title | |||||
| #' @param ... further arguments passed to base_plot | |||||
| #' | |||||
| #' @return a gif | |||||
| #' | |||||
| #' @examples | |||||
| #' NULL | |||||
| animate_plot <- function(d, title = "", ...) { | |||||
| base_plot(d, title, ...) + | |||||
| transition_states(.frame, 2, 1) + | |||||
| enter_fade() + | |||||
| exit_fade() + | |||||
| ease_aes("sine-in-out") | |||||
| } | |||||
| #' Prints the tiles for a processed dataset | |||||
| #' | |||||
| #' @param d a processed dataset | |||||
| #' @param title the title of the plot | |||||
| #' @param ... further arguments | |||||
| #' | |||||
| #' @return a ggplot | |||||
| #' | |||||
| #' @examples | |||||
| #' NULL | |||||
| base_plot <- function(d, title = "", ...) { | |||||
| dots <- list(...) | |||||
| if ("text_family" %in% names(dots)) { | |||||
| text_family <- dots$text_family | |||||
| } else { | |||||
| text_family <- "Fira Sans" | |||||
| } | |||||
| if ("title_family" %in% names(dots)) { | |||||
| title_family <- dots$title_family | |||||
| } else { | |||||
| title_family <- "Fira Mono" | |||||
| } | |||||
| if (!".alpha" %in% names(d)) d <- d %>% mutate(.alpha = 1) | |||||
| ggplot(d, aes(x = .x, group = .id_long, y = .y, fill = .color, alpha = .alpha)) + | |||||
| geom_tile(width = 0.9, height = 0.9) + | |||||
| coord_equal() + | |||||
| geom_text(data = d %>% filter(!is.na(val)), aes(label = val), color = "white", | |||||
| family = text_family, size = 20, fontface = "bold") + | |||||
| scale_fill_identity() + | |||||
| scale_alpha_identity() + | |||||
| labs(title = title) + | |||||
| theme_void() + | |||||
| theme(plot.title = element_text(family = title_family, hjust = 0.5, size = 30)) | |||||
| } |
| #' Preprocess data | |||||
| #' | |||||
| #' @param x a left dataset | |||||
| #' @param y a right dataset | |||||
| #' @param by a by argument for joins / set operations | |||||
| #' | |||||
| #' @return a preprocessed dataset | |||||
| #' | |||||
| #' @examples | |||||
| #' NULL | |||||
| preprocess_data <- function(x, y, by) { | |||||
| xvars <- names(x) %>% str_subset("^[^\\.]") | |||||
| yvars <- names(y) %>% str_subset("^[^\\.]") | |||||
| x <- x %>% | |||||
| unite(one_of(by), col = ".id", remove = FALSE) %>% | |||||
| unite(one_of(xvars), col = ".id_long", remove = FALSE) | |||||
| y <- y %>% | |||||
| unite(one_of(by), col = ".id", remove = FALSE) %>% | |||||
| unite(one_of(yvars), col = ".id_long", remove = FALSE) | |||||
| ids <- unique(c(x$.id, y$.id)) | |||||
| x_ <- process_data(x, ids, by) %>% | |||||
| mutate(.id_long = paste(.id_long, .side, .r, sep = "_")) | |||||
| y_ <- process_data(y, ids, by) %>% | |||||
| mutate(.x = .x + ncol(x), | |||||
| .id_long = paste(.id_long, .side, .r, sep = "_")) | |||||
| return(list(x = x_, y = y_)) | |||||
| } | |||||
| #' Processes the data | |||||
| #' | |||||
| #' @param x a preprocessed dataset | |||||
| #' @param ids a vector of ids | |||||
| #' @param by a vector of by-arguments | |||||
| #' @param width the width of the tiles | |||||
| #' @param side the side (x or y, lhs or rhs, etc) | |||||
| #' | |||||
| #' @return a data_frame including all necessary information | |||||
| #' | |||||
| #' @examples | |||||
| #' NULL | |||||
| process_data <- function(x, ids, by, width = 1, side = NA) { | |||||
| if (is.na(side)) side <- deparse(substitute(x)) | |||||
| x_names <- names(x) %>% str_subset("^[^\\.]") | |||||
| x_keys <- 1:length(x_names) | |||||
| names(x_keys) <- x_names | |||||
| special_vars <- names(x) %>% str_subset("^\\.") | |||||
| x <- x %>% | |||||
| mutate(.r = row_number()) %>% | |||||
| gather_(key = "col", value = "val", names(x) %>% str_subset("^[^.]")) %>% | |||||
| mutate(.x = x_keys[col], | |||||
| .y = -.r) %>% | |||||
| bind_rows(data_frame(.id = ".header", | |||||
| .id_long = paste(".header", x_names, sep = "_"), | |||||
| .r = 0, col = x_names, val = x_names, | |||||
| .x = x_keys, .y = 0), .) %>% | |||||
| mutate(.width = width, | |||||
| .side = side) | |||||
| add_color(x, ids, by) | |||||
| } | |||||
| #' Adds Color to a processed data_frame | |||||
| #' | |||||
| #' @param x a processed data_frame | |||||
| #' @param ids a vector of ids for the color-matching | |||||
| #' @param by a vector of column names that constitute the by-argument of joins/sets | |||||
| #' @param color_header color for the header | |||||
| #' @param color_other color for "inactive" values | |||||
| #' @param color_missing color for missing values | |||||
| #' | |||||
| #' @return the processed data_frame with a new column .color | |||||
| #' | |||||
| #' @examples | |||||
| #' NULL | |||||
| add_color <- function(x, ids, by, color_header = "#bdbdbd", color_other = "#d0d0d0", color_missing = "#ffffff") { | |||||
| colors <- c(color_header, scales::brewer_pal(type = "qual", "Set1")(length(ids))) | |||||
| names(colors) <- c(".header", ids) | |||||
| x %>% | |||||
| mutate(.color = ifelse(is.na(val), color_missing, colors[.id]), | |||||
| .color = ifelse(col %in% by, .color, color_other)) | |||||
| } |
| source(here::here("R/00_base_join.R")) | |||||
| rj_joined_dfs <- right_join(x, y, "id") %>% | |||||
| proc_data("y") %>% | |||||
| mutate(frame = 2, .x = .x + 1) | |||||
| rj_extra_blocks <- inner_join(x, y, "id") %>% | |||||
| select(id) %>% | |||||
| proc_data("x") %>% | |||||
| mutate(frame = 2, .x = .x + 1) | |||||
| rj <- bind_rows( | |||||
| initial_join_dfs, | |||||
| rj_joined_dfs, | |||||
| rj_extra_blocks | |||||
| ) %>% | |||||
| filter(!is.na(value)) %>% | |||||
| mutate( | |||||
| .id = ifelse(label == "x", label, .id), | |||||
| removed = as.integer(grepl("3", value)) | |||||
| ) %>% | |||||
| arrange(removed, value, .id, frame) %>% | |||||
| plot_data("right_join(x, y)") %>% | |||||
| animate_plot() | |||||
| rj <- animate(rj) | |||||
| anim_save(here::here("images", "right-join.gif"), rj) | |||||
| rj_g <- plot_data(rj_joined_dfs, "right_join(x, y)") | |||||
| save_static_plot(rj_g, "right-join") |
| source(here::here("R/00_base_join.R")) | |||||
| sj_joined_df <- semi_join(x, y, "id") %>% | |||||
| proc_data("x") %>% | |||||
| mutate(frame = 2, .x = .x + 1.5) | |||||
| sj_extra_blocks <- inner_join(x, y, "id") %>% | |||||
| select(id) %>% | |||||
| proc_data("y") %>% | |||||
| mutate(frame = 2, .x = .x + 1.5) | |||||
| sj <- bind_rows( | |||||
| initial_join_dfs, | |||||
| sj_joined_df, | |||||
| sj_extra_blocks | |||||
| ) %>% | |||||
| arrange(value) %>% | |||||
| plot_data("semi_join(x, y)") %>% | |||||
| animate_plot() | |||||
| sj <- animate(sj) | |||||
| anim_save(here::here("images", "semi-join.gif"), sj) | |||||
| # Static Images | |||||
| sj_g <- semi_join(x, y, "id") %>% | |||||
| proc_data() %>% | |||||
| mutate(.x = .x + 1.5) %>% | |||||
| plot_data_join("semi_join(x, y)") | |||||
| save_static_plot(sj_g, "semi-join") |
| source(here::here("R/00_base_set.R")) | |||||
| # ---- setdiff(x, y) ---- | |||||
| # Dim elements unique to y | |||||
| setd_step2 <- initial_set_dfs %>% | |||||
| mutate( | |||||
| frame = 2, | |||||
| alpha = case_when( | |||||
| .y == -1 ~ 0.55, | |||||
| .id == "y" ~ 0.15, | |||||
| TRUE ~ 1 | |||||
| ) | |||||
| ) | |||||
| # Merge, dim overlapping elements | |||||
| setd_step3 <- initial_set_dfs %>% | |||||
| filter(!(.id == "y" & .y == -2)) %>% | |||||
| mutate( | |||||
| frame = 3, | |||||
| alpha = ifelse(.y == -1, 0.25, 1), | |||||
| .x = ifelse(.id == "y", .x - 3, .x), | |||||
| .x = .x + 1.5 | |||||
| ) | |||||
| # Result of setdiff | |||||
| setd_step4 <- setdiff(x, y) %>% | |||||
| proc_data_set("xy") %>% | |||||
| mutate(frame = 4, .x = .x + 1.5) | |||||
| setd <- bind_rows( | |||||
| initial_set_dfs, | |||||
| setd_step2, | |||||
| setd_step3, | |||||
| setd_step4 | |||||
| ) %>% | |||||
| mutate(alpha = ifelse(is.na(alpha), 1, alpha)) %>% | |||||
| arrange(frame, desc(.y), desc(.id)) %>% | |||||
| plot_data_set(., "setdiff(x, y)") %>% | |||||
| animate_plot() | |||||
| setd <- animate(setd) | |||||
| anim_save(here::here("images", "setdiff.gif"), setd) | |||||
| setd_g <- setdiff(x, y) %>% | |||||
| proc_data_set() %>% | |||||
| mutate(.x = .x + 1.5) %>% | |||||
| plot_data_set("setdiff(x, y)") | |||||
| save_static_plot(setd_g, "setdiff") | |||||
| # ---- setdiff(y, x) ---- | |||||
| # Dim elements unique to x | |||||
| setd2_step2 <- initial_set_dfs %>% | |||||
| mutate( | |||||
| frame = 2, | |||||
| alpha = case_when( | |||||
| .y == -1 ~ 0.55, | |||||
| .id == "x" ~ 0.15, | |||||
| TRUE ~ 1 | |||||
| ) | |||||
| ) | |||||
| # Merge, dim overlapping elements | |||||
| setd2_step3 <- initial_set_dfs %>% | |||||
| filter(!(.id == "x" & .y <= -2)) %>% | |||||
| mutate( | |||||
| frame = 3, | |||||
| alpha = ifelse(.y == -1, 0.25, 1), | |||||
| .x = ifelse(.id == "y", .x - 3, .x), | |||||
| .x = .x + 1.5 | |||||
| ) | |||||
| # Result of setdiff | |||||
| setd2_step4 <- setdiff(y, x) %>% | |||||
| proc_data_set("xy") %>% | |||||
| mutate(frame = 4, .x = .x + 1.5) | |||||
| setd2 <- bind_rows( | |||||
| initial_set_dfs, | |||||
| setd2_step2, | |||||
| setd2_step3, | |||||
| setd2_step4 | |||||
| ) %>% | |||||
| mutate(alpha = ifelse(is.na(alpha), 1, alpha)) %>% | |||||
| arrange(frame, desc(.y), .id) %>% | |||||
| plot_data_set(., "setdiff(y, x)") %>% | |||||
| animate_plot() | |||||
| setd2 <- animate(setd2) | |||||
| anim_save(here::here("images", "setdiff-rev.gif"), setd2) | |||||
| setd2_g <- setdiff(x, y) %>% | |||||
| proc_data_set() %>% | |||||
| mutate(.x = .x + 1.5) %>% | |||||
| plot_data_set("setdiff(y, x)") | |||||
| save_static_plot(setd2_g, "setdiff-rev") |
| source(here::here("R/00_base_set.R")) | |||||
| # ---- union(x, y) ---- | |||||
| uxy <- bind_rows( | |||||
| initial_set_dfs, | |||||
| union(x, y) %>% proc_data_set("xy") %>% mutate(frame = 2, .x = .x + 1.5), | |||||
| intersect(x, y) %>% proc_data_set("xy") %>% mutate(frame = 2, .y = -4, .x = .x + 1.5) | |||||
| ) %>% | |||||
| plot_data_set("union(x, y)", ylims = ylim(-4.5, -0.5)) %>% | |||||
| animate_plot() | |||||
| uxy <- animate(uxy) | |||||
| anim_save(here::here("images", "union.gif"), uxy) | |||||
| uxy_g <- union(x, y) %>% | |||||
| proc_data_set() %>% | |||||
| mutate(.x = .x + 1.5) %>% | |||||
| plot_data_set("union(x, y)", ylims = ylim(-0.5, -4.5)) | |||||
| save_static_plot(uxy_g, "union") | |||||
| # ---- union(y, x) ---- | |||||
| uyx <- bind_rows( | |||||
| initial_set_dfs, | |||||
| union(y, x) %>% proc_data_set("xy") %>% mutate(frame = 2, .x = .x + 1.5), | |||||
| intersect(y, x) %>% proc_data_set("xy") %>% mutate(frame = 2, .y = -4, .x = .x + 1.5) | |||||
| ) %>% | |||||
| plot_data_set("union(y, x)", ylims = ylim(-4.5, -0.5)) %>% | |||||
| animate_plot() | |||||
| uyx <- animate(uyx) | |||||
| anim_save(here::here("images", "union-rev.gif"), uyx) | |||||
| uyx_g <- union(y, x) %>% | |||||
| proc_data_set() %>% | |||||
| mutate(.x = .x + 1.5) %>% | |||||
| plot_data_set("union(y, x)", ylims = ylim(-4.5, -0.5)) | |||||
| save_static_plot(uyx_g, "union-rev") |
| source(here::here("R/00_base_set.R")) | |||||
| ua <- bind_rows( | |||||
| initial_set_dfs, | |||||
| initial_set_dfs %>% mutate(frame = 2, .y = ifelse(.id == "y", .y - 3, .y)), # fly y down | |||||
| proc_data_set(x, "ux") %>% mutate(frame = 3, .x = .x + 1.5), # merge | |||||
| proc_data_set(y, "uy") %>% mutate(frame = 3, .x = .x + 1.5, .y = .y - 3), # un-merge | |||||
| initial_set_dfs %>% mutate(frame = 4, .y = ifelse(.id == "y", .y - 3, .y)) # fly y up | |||||
| ) %>% | |||||
| arrange(desc(frame)) %>% | |||||
| plot_data_set("union_all(x, y)", ylims = ylim(-5.5, -0.5)) + | |||||
| transition_states(frame, 1, c(1, 0, 1, 0)) | |||||
| ua <- animate(ua) | |||||
| anim_save(here::here("images", "union-all.gif"), ua) | |||||
| ua_g <- union_all(x, y) %>% | |||||
| proc_data_set() %>% | |||||
| mutate(.x = .x + 1.5) %>% | |||||
| plot_data_set("union_all(x, y)", ylims = ylim(-5.5, -0.5)) | |||||
| save_static_plot(ua_g, "union-all") |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/process_data_helpers.R | |||||
| \name{add_color} | |||||
| \alias{add_color} | |||||
| \title{Adds Color to a processed data_frame} | |||||
| \usage{ | |||||
| add_color(x, ids, by, color_header = "#bdbdbd", | |||||
| color_other = "#d0d0d0", color_missing = "#ffffff") | |||||
| } | |||||
| \arguments{ | |||||
| \item{x}{a processed data_frame} | |||||
| \item{ids}{a vector of ids for the color-matching} | |||||
| \item{by}{a vector of column names that constitute the by-argument of joins/sets} | |||||
| \item{color_header}{color for the header} | |||||
| \item{color_other}{color for "inactive" values} | |||||
| \item{color_missing}{color for missing values} | |||||
| } | |||||
| \value{ | |||||
| the processed data_frame with a new column .color | |||||
| } | |||||
| \description{ | |||||
| Adds Color to a processed data_frame | |||||
| } | |||||
| \examples{ | |||||
| NULL | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/animate_joins.R | |||||
| \name{animate_anti_join} | |||||
| \alias{animate_anti_join} | |||||
| \title{Animates an anti join} | |||||
| \usage{ | |||||
| animate_anti_join(x, y, by, export = "gif", ...) | |||||
| } | |||||
| \arguments{ | |||||
| \item{x}{the x dataset} | |||||
| \item{y}{the y dataset} | |||||
| \item{by}{the by arguments for the join} | |||||
| \item{export}{the export type, either gif, first or last. The latter two | |||||
| export ggplots of the first/last state of the join} | |||||
| \item{...}{further arguments passed to base_plot} | |||||
| } | |||||
| \value{ | |||||
| either a gif or a ggplot | |||||
| } | |||||
| \description{ | |||||
| Animates an anti join | |||||
| } | |||||
| \examples{ | |||||
| x <- data_frame( | |||||
| id = 1:3, | |||||
| x = paste0("x", 1:3) | |||||
| ) | |||||
| y <- data_frame( | |||||
| id = (1:4)[-3], | |||||
| y = paste0("y", (1:4)[-3]) | |||||
| ) | |||||
| animate_anti_join(x, y, by = "id", export = "first") | |||||
| animate_anti_join(x, y, by = "id", export = "last") | |||||
| \dontrun{ | |||||
| # to save the ggplot, use | |||||
| aj <- animate_anti_join(x, y, by = "id", export = "last") | |||||
| ggsave("anti-join.pdf", aj) | |||||
| animate_anti_join(x, y, by = "id", export = "gif") | |||||
| # to save the gif, use | |||||
| aj <- animate_anti_join(x, y, by = "id", export = "gif") | |||||
| anim_save(aj, "anti-join.gif") | |||||
| } | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/animate_joins.R | |||||
| \name{animate_full_join} | |||||
| \alias{animate_full_join} | |||||
| \title{Animates a full join} | |||||
| \usage{ | |||||
| animate_full_join(x, y, by, export = "gif", ...) | |||||
| } | |||||
| \arguments{ | |||||
| \item{x}{the x dataset} | |||||
| \item{y}{the y dataset} | |||||
| \item{by}{the by arguments for the join} | |||||
| \item{export}{the export type, either gif, first or last. The latter two | |||||
| export ggplots of the first/last state of the join} | |||||
| \item{...}{further arguments passed to base_plot} | |||||
| } | |||||
| \value{ | |||||
| either a gif or a ggplot | |||||
| } | |||||
| \description{ | |||||
| Animates a full join | |||||
| } | |||||
| \examples{ | |||||
| x <- data_frame( | |||||
| id = 1:3, | |||||
| x = paste0("x", 1:3) | |||||
| ) | |||||
| y <- data_frame( | |||||
| id = (1:4)[-3], | |||||
| y = paste0("y", (1:4)[-3]) | |||||
| ) | |||||
| animate_full_join(x, y, by = "id", export = "first") | |||||
| animate_full_join(x, y, by = "id", export = "last") | |||||
| \dontrun{ | |||||
| # to save the ggplot, use | |||||
| fj <- animate_full_join(x, y, by = "id", export = "last") | |||||
| ggsave("full-join.pdf", fj) | |||||
| animate_full_join(x, y, by = "id", export = "gif") | |||||
| # to save the gif, use | |||||
| fj <- animate_full_join(x, y, by = "id", export = "gif") | |||||
| anim_save(fj, "full-join.gif") | |||||
| } | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/animate_joins.R | |||||
| \name{animate_inner_join} | |||||
| \alias{animate_inner_join} | |||||
| \title{Animates an inner join} | |||||
| \usage{ | |||||
| animate_inner_join(x, y, by, export = "gif", ...) | |||||
| } | |||||
| \arguments{ | |||||
| \item{x}{the x dataset} | |||||
| \item{y}{the y dataset} | |||||
| \item{by}{the by arguments for the join} | |||||
| \item{export}{the export type, either gif, first or last. The latter two | |||||
| export ggplots of the first/last state of the join} | |||||
| \item{...}{further arguments passed to base_plot} | |||||
| } | |||||
| \value{ | |||||
| either a gif or a ggplot | |||||
| } | |||||
| \description{ | |||||
| Animates an inner join | |||||
| } | |||||
| \examples{ | |||||
| x <- data_frame( | |||||
| id = 1:3, | |||||
| x = paste0("x", 1:3) | |||||
| ) | |||||
| y <- data_frame( | |||||
| id = (1:4)[-3], | |||||
| y = paste0("y", (1:4)[-3]) | |||||
| ) | |||||
| animate_inner_join(x, y, by = "id", export = "first") | |||||
| animate_inner_join(x, y, by = "id", export = "last") | |||||
| \dontrun{ | |||||
| # to save the ggplot, use | |||||
| ij <- animate_inner_join(x, y, by = "id", export = "last") | |||||
| ggsave("inner-join.pdf", ij) | |||||
| animate_inner_join(x, y, by = "id", export = "gif") | |||||
| # to save the gif, use | |||||
| ij <- animate_inner_join(x, y, by = "id", export = "gif") | |||||
| anim_save(ij, "inner-join.gif") | |||||
| } | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/animate_sets.R | |||||
| \name{animate_intersect} | |||||
| \alias{animate_intersect} | |||||
| \title{Animates an intersect set} | |||||
| \usage{ | |||||
| animate_intersect(x, y, export = "gif", ...) | |||||
| } | |||||
| \arguments{ | |||||
| \item{x}{the x dataset} | |||||
| \item{y}{the y dataset} | |||||
| \item{export}{the export type, either gif, first or last. The latter two | |||||
| export ggplots of the first/last state of the join} | |||||
| \item{...}{further argument passed to base_plot} | |||||
| } | |||||
| \value{ | |||||
| either a gif or a ggplot | |||||
| } | |||||
| \description{ | |||||
| Animates an intersect set | |||||
| } | |||||
| \examples{ | |||||
| x <- data_frame( | |||||
| id = 1:3, | |||||
| x = paste0("x", 1:3) | |||||
| ) | |||||
| y <- data_frame( | |||||
| id = (1:4)[-3], | |||||
| y = paste0("y", (1:4)[-3]) | |||||
| ) | |||||
| animate_intersect(x, y, by = "id", export = "first") | |||||
| animate_intersect(x, y, by = "id", export = "last") | |||||
| \dontrun{ | |||||
| # to save the ggplot, use | |||||
| ints <- animate_intersect(x, y, by = "id", export = "last") | |||||
| ggsave("intersect.pdf", ints) | |||||
| animate_intersect(x, y, by = "id", export = "gif") | |||||
| # to save the gif, use | |||||
| ints <- animate_union_all(x, y, by = "id", export = "gif") | |||||
| anim_save(ints, "intersect.gif") | |||||
| } | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/animate_helpers.R | |||||
| \name{animate_join} | |||||
| \alias{animate_join} | |||||
| \title{Animates a join - wrapper function} | |||||
| \usage{ | |||||
| animate_join(x, y, by, type, export = "gif", ...) | |||||
| } | |||||
| \arguments{ | |||||
| \item{x}{left dataset} | |||||
| \item{y}{right dataset} | |||||
| \item{by}{by arguments for the join} | |||||
| \item{type}{type of the join, i.e., left_join, right_join, etc.} | |||||
| \item{export}{if the function exports a gif, the first, or last picture} | |||||
| \item{...}{further arguments passed to base_plot} | |||||
| } | |||||
| \value{ | |||||
| either a gif or a ggplot | |||||
| } | |||||
| \description{ | |||||
| Animates a join - wrapper function | |||||
| } | |||||
| \examples{ | |||||
| NULL | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/animate_joins.R | |||||
| \name{animate_left_join} | |||||
| \alias{animate_left_join} | |||||
| \title{Animates a left join} | |||||
| \usage{ | |||||
| animate_left_join(x, y, by, export = "gif", ...) | |||||
| } | |||||
| \arguments{ | |||||
| \item{x}{the x dataset} | |||||
| \item{y}{the y dataset} | |||||
| \item{by}{the by arguments for the join} | |||||
| \item{export}{the export type, either gif, first or last. The latter two | |||||
| export ggplots of the first/last state of the join} | |||||
| \item{...}{further arguments passed to base_plot} | |||||
| } | |||||
| \value{ | |||||
| either a gif or a ggplot | |||||
| } | |||||
| \description{ | |||||
| Animates a left join | |||||
| } | |||||
| \examples{ | |||||
| x <- data_frame( | |||||
| id = 1:3, | |||||
| x = paste0("x", 1:3) | |||||
| ) | |||||
| y <- data_frame( | |||||
| id = (1:4)[-3], | |||||
| y = paste0("y", (1:4)[-3]) | |||||
| ) | |||||
| animate_left_join(x, y, by = "id", export = "first") | |||||
| animate_left_join(x, y, by = "id", export = "last") | |||||
| \dontrun{ | |||||
| # to save the ggplot, use | |||||
| lj <- animate_left_join(x, y, by = "id", export = "last") | |||||
| ggsave("left-join.pdf", lj) | |||||
| animate_left_join(x, y, by = "id", export = "gif") | |||||
| # to save the gif, use | |||||
| lj <- animate_left_join(x, y, by = "id", export = "gif") | |||||
| anim_save(lj, "left-join.gif") | |||||
| } | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/plot_helpers.R | |||||
| \name{animate_plot} | |||||
| \alias{animate_plot} | |||||
| \title{Animates a plot} | |||||
| \usage{ | |||||
| animate_plot(d, title = "", ...) | |||||
| } | |||||
| \arguments{ | |||||
| \item{d}{a preprocessed dataset} | |||||
| \item{title}{the plot title} | |||||
| \item{...}{further arguments passed to base_plot} | |||||
| } | |||||
| \value{ | |||||
| a gif | |||||
| } | |||||
| \description{ | |||||
| Animates a plot | |||||
| } | |||||
| \examples{ | |||||
| NULL | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/animate_joins.R | |||||
| \name{animate_right_join} | |||||
| \alias{animate_right_join} | |||||
| \title{Animates a right join} | |||||
| \usage{ | |||||
| animate_right_join(x, y, by, export = "gif", ...) | |||||
| } | |||||
| \arguments{ | |||||
| \item{x}{the x dataset} | |||||
| \item{y}{the y dataset} | |||||
| \item{by}{the by arguments for the join} | |||||
| \item{export}{the export type, either gif, first or last. The latter two | |||||
| export ggplots of the first/last state of the join} | |||||
| \item{...}{further arguments passed to base_plot} | |||||
| } | |||||
| \value{ | |||||
| either a gif or a ggplot | |||||
| } | |||||
| \description{ | |||||
| Animates a right join | |||||
| } | |||||
| \examples{ | |||||
| x <- data_frame( | |||||
| id = 1:3, | |||||
| x = paste0("x", 1:3) | |||||
| ) | |||||
| y <- data_frame( | |||||
| id = (1:4)[-3], | |||||
| y = paste0("y", (1:4)[-3]) | |||||
| ) | |||||
| animate_right_join(x, y, by = "id", export = "first") | |||||
| animate_right_join(x, y, by = "id", export = "last") | |||||
| \dontrun{ | |||||
| # to save the ggplot, use | |||||
| rj <- animate_right_join(x, y, by = "id", export = "last") | |||||
| ggsave("right-join.pdf", rj) | |||||
| animate_right_join(x, y, by = "id", export = "gif") | |||||
| # to save the gif, use | |||||
| rj <- animate_right_join(x, y, by = "id", export = "gif") | |||||
| anim_save(rj, "right-join.gif") | |||||
| } | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/animate_joins.R | |||||
| \name{animate_semi_join} | |||||
| \alias{animate_semi_join} | |||||
| \title{Animates a semi join} | |||||
| \usage{ | |||||
| animate_semi_join(x, y, by, export = "gif", ...) | |||||
| } | |||||
| \arguments{ | |||||
| \item{x}{the x dataset} | |||||
| \item{y}{the y dataset} | |||||
| \item{by}{the by arguments for the join} | |||||
| \item{export}{the export type, either gif, first or last. The latter two | |||||
| export ggplots of the first/last state of the join} | |||||
| \item{...}{further arguments passed to base_plot} | |||||
| } | |||||
| \value{ | |||||
| either a gif or a ggplot | |||||
| } | |||||
| \description{ | |||||
| Animates a semi join | |||||
| } | |||||
| \examples{ | |||||
| x <- data_frame( | |||||
| id = 1:3, | |||||
| x = paste0("x", 1:3) | |||||
| ) | |||||
| y <- data_frame( | |||||
| id = (1:4)[-3], | |||||
| y = paste0("y", (1:4)[-3]) | |||||
| ) | |||||
| animate_semi_join(x, y, by = "id", export = "first") | |||||
| animate_semi_join(x, y, by = "id", export = "last") | |||||
| \dontrun{ | |||||
| # to save the ggplot, use | |||||
| sj <- animate_semi_join(x, y, by = "id", export = "last") | |||||
| ggsave("semi-join.pdf", sj) | |||||
| animate_semi_join(x, y, by = "id", export = "gif") | |||||
| # to save the gif, use | |||||
| sj <- animate_semi_join(x, y, by = "id", export = "gif") | |||||
| anim_save(sj, "semi-join.gif") | |||||
| } | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/animate_helpers.R | |||||
| \name{animate_set} | |||||
| \alias{animate_set} | |||||
| \title{Animates a set - wrapper function} | |||||
| \usage{ | |||||
| animate_set(x, y, type, export = "gif", ...) | |||||
| } | |||||
| \arguments{ | |||||
| \item{x}{left dataset} | |||||
| \item{y}{right dataset} | |||||
| \item{type}{type of the set, i.e., intersect, setdiff, etc.} | |||||
| \item{export}{if the function exports a gif, the first, or last picture} | |||||
| \item{...}{further arguments passed to base_plot} | |||||
| } | |||||
| \value{ | |||||
| either a gif or a ggplot | |||||
| } | |||||
| \description{ | |||||
| Animates a set - wrapper function | |||||
| } | |||||
| \examples{ | |||||
| NULL | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/animate_sets.R | |||||
| \name{animate_setdiff} | |||||
| \alias{animate_setdiff} | |||||
| \title{Animates a setdiff set} | |||||
| \usage{ | |||||
| animate_setdiff(x, y, export = "gif", ...) | |||||
| } | |||||
| \arguments{ | |||||
| \item{x}{the x dataset} | |||||
| \item{y}{the y dataset} | |||||
| \item{export}{the export type, either gif, first or last. The latter two | |||||
| export ggplots of the first/last state of the join} | |||||
| \item{...}{further argument passed to base_plot} | |||||
| } | |||||
| \value{ | |||||
| either a gif or a ggplot | |||||
| } | |||||
| \description{ | |||||
| Animates a setdiff set | |||||
| } | |||||
| \examples{ | |||||
| x <- data_frame( | |||||
| id = 1:3, | |||||
| x = paste0("x", 1:3) | |||||
| ) | |||||
| y <- data_frame( | |||||
| id = (1:4)[-3], | |||||
| y = paste0("y", (1:4)[-3]) | |||||
| ) | |||||
| animate_setdiff(x, y, by = "id", export = "first") | |||||
| animate_setdiff(x, y, by = "id", export = "last") | |||||
| \dontrun{ | |||||
| # to save the ggplot, use | |||||
| setd <- animate_setdiff(x, y, by = "id", export = "last") | |||||
| ggsave("setdiff.pdf", setd) | |||||
| animate_setdiff(x, y, by = "id", export = "gif") | |||||
| # to save the gif, use | |||||
| setd <- animate_union_all(x, y, by = "id", export = "gif") | |||||
| anim_save(setd, "setdiff.gif") | |||||
| } | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/animate_sets.R | |||||
| \name{animate_union} | |||||
| \alias{animate_union} | |||||
| \title{Animates a union set} | |||||
| \usage{ | |||||
| animate_union(x, y, export = "gif", ...) | |||||
| } | |||||
| \arguments{ | |||||
| \item{x}{the x dataset} | |||||
| \item{y}{the y dataset} | |||||
| \item{export}{the export type, either gif, first or last. The latter two | |||||
| export ggplots of the first/last state of the join} | |||||
| \item{...}{further argument passed to base_plot} | |||||
| } | |||||
| \value{ | |||||
| either a gif or a ggplot | |||||
| } | |||||
| \description{ | |||||
| Animates a union set | |||||
| } | |||||
| \examples{ | |||||
| x <- data_frame( | |||||
| id = 1:3, | |||||
| x = paste0("x", 1:3) | |||||
| ) | |||||
| y <- data_frame( | |||||
| id = (1:4)[-3], | |||||
| y = paste0("y", (1:4)[-3]) | |||||
| ) | |||||
| animate_union(x, y, by = "id", export = "first") | |||||
| animate_union(x, y, by = "id", export = "last") | |||||
| \dontrun{ | |||||
| # to save the ggplot, use | |||||
| un <- animate_union(x, y, by = "id", export = "last") | |||||
| ggsave("union.pdf", un) | |||||
| animate_union(x, y, by = "id", export = "gif") | |||||
| # to save the gif, use | |||||
| un <- animate_union(x, y, by = "id", export = "gif") | |||||
| anim_save(un, "union.gif") | |||||
| } | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/animate_sets.R | |||||
| \name{animate_union_all} | |||||
| \alias{animate_union_all} | |||||
| \title{Animates a union-all set} | |||||
| \usage{ | |||||
| animate_union_all(x, y, export = "gif", ...) | |||||
| } | |||||
| \arguments{ | |||||
| \item{x}{the x dataset} | |||||
| \item{y}{the y dataset} | |||||
| \item{export}{the export type, either gif, first or last. The latter two | |||||
| export ggplots of the first/last state of the join} | |||||
| \item{...}{further argument passed to base_plot} | |||||
| } | |||||
| \value{ | |||||
| either a gif or a ggplot | |||||
| } | |||||
| \description{ | |||||
| Animates a union-all set | |||||
| } | |||||
| \examples{ | |||||
| x <- data_frame( | |||||
| id = 1:3, | |||||
| x = paste0("x", 1:3) | |||||
| ) | |||||
| y <- data_frame( | |||||
| id = (1:4)[-3], | |||||
| y = paste0("y", (1:4)[-3]) | |||||
| ) | |||||
| animate_union_all(x, y, by = "id", export = "first") | |||||
| animate_union_all(x, y, by = "id", export = "last") | |||||
| \dontrun{ | |||||
| # to save the ggplot, use | |||||
| un <- animate_union_all(x, y, by = "id", export = "last") | |||||
| ggsave("union-all.pdf", un) | |||||
| animate_union_all(x, y, by = "id", export = "gif") | |||||
| # to save the gif, use | |||||
| un <- animate_union_all(x, y, by = "id", export = "gif") | |||||
| anim_save(un, "union-all.gif") | |||||
| } | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/plot_helpers.R | |||||
| \name{base_plot} | |||||
| \alias{base_plot} | |||||
| \title{Prints the tiles for a processed dataset} | |||||
| \usage{ | |||||
| base_plot(d, title = "", ...) | |||||
| } | |||||
| \arguments{ | |||||
| \item{d}{a processed dataset} | |||||
| \item{title}{the title of the plot} | |||||
| \item{...}{further arguments} | |||||
| } | |||||
| \value{ | |||||
| a ggplot | |||||
| } | |||||
| \description{ | |||||
| Prints the tiles for a processed dataset | |||||
| } | |||||
| \examples{ | |||||
| NULL | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/combine.R | |||||
| \name{combine} | |||||
| \alias{combine} | |||||
| \title{Combines two processed datasets and combines them for a given method} | |||||
| \usage{ | |||||
| combine(lhs, rhs, type) | |||||
| } | |||||
| \arguments{ | |||||
| \item{lhs}{the left-hand side dataset} | |||||
| \item{rhs}{the righ-hand side dataset} | |||||
| \item{type}{a string of the desired combination method, allowed are all dplyr | |||||
| joins or sets} | |||||
| } | |||||
| \value{ | |||||
| processed dataset of the combined values | |||||
| } | |||||
| \description{ | |||||
| Combines two processed datasets and combines them for a given method | |||||
| } | |||||
| \examples{ | |||||
| NULL | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/process_data_helpers.R | |||||
| \name{preprocess_data} | |||||
| \alias{preprocess_data} | |||||
| \title{Preprocess data} | |||||
| \usage{ | |||||
| preprocess_data(x, y, by) | |||||
| } | |||||
| \arguments{ | |||||
| \item{x}{a left dataset} | |||||
| \item{y}{a right dataset} | |||||
| \item{by}{a by argument for joins / set operations} | |||||
| } | |||||
| \value{ | |||||
| a preprocessed dataset | |||||
| } | |||||
| \description{ | |||||
| Preprocess data | |||||
| } | |||||
| \examples{ | |||||
| NULL | |||||
| } |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/process_data_helpers.R | |||||
| \name{process_data} | |||||
| \alias{process_data} | |||||
| \title{Processes the data} | |||||
| \usage{ | |||||
| process_data(x, ids, by, width = 1, side = NA) | |||||
| } | |||||
| \arguments{ | |||||
| \item{x}{a preprocessed dataset} | |||||
| \item{ids}{a vector of ids} | |||||
| \item{by}{a vector of by-arguments} | |||||
| \item{width}{the width of the tiles} | |||||
| \item{side}{the side (x or y, lhs or rhs, etc)} | |||||
| } | |||||
| \value{ | |||||
| a data_frame including all necessary information | |||||
| } | |||||
| \description{ | |||||
| Processes the data | |||||
| } | |||||
| \examples{ | |||||
| NULL | |||||
| } |