| frame_labels <- c(sequence[["operation"]], sequence[["reverse_operation"]]) | frame_labels <- c(sequence[["operation"]], sequence[["reverse_operation"]]) | ||||
| title_string <- "{ifelse(transitioning, previous_state, ifelse(grepl('gather', next_state), 'Wide', 'Long'))}" | title_string <- "{ifelse(transitioning, previous_state, ifelse(grepl('gather', next_state), 'Wide', 'Long'))}" | ||||
| tl <- 2 | |||||
| sl <- 1 | |||||
| } else { | } else { | ||||
| xshift <- 2 | xshift <- 2 | ||||
| ) | ) | ||||
| title_string <- "{gsub('\\\\) [a-zA-Z]+$', ')', previous_state)}" | title_string <- "{gsub('\\\\) [a-zA-Z]+$', ')', previous_state)}" | ||||
| tl <- length(unique(anim_df$.frame)) * 2 | |||||
| sl <- 1 | |||||
| } | } | ||||
| frame_levels <- anim_df$.frame %>% unique() | frame_levels <- anim_df$.frame %>% unique() | ||||
| labels = frame_labels)) | labels = frame_labels)) | ||||
| if (export == "gif") { | if (export == "gif") { | ||||
| animate_plot(anim_df, title = title_string) #... | |||||
| animate_plot(anim_df, title = title_string, transition_length = tl, state_length = sl) #... | |||||
| } else if (export == "first") { | } else if (export == "first") { | ||||
| static_plot(state_start) #.... | static_plot(state_start) #.... | ||||
| } else if (export == "last") { | } else if (export == "last") { |
| ## Set Operations | ## Set Operations | ||||
| ``` r | ``` r | ||||
| x <- tibble::tribble( | |||||
| ~x, ~y, | |||||
| "1", "a", | |||||
| "1", "b", | |||||
| "2", "a" | |||||
| x <- data_frame( | |||||
| x = c(1, 1, 2), | |||||
| y = c("a", "b", "a") | |||||
| ) | ) | ||||
| y <- tibble::tribble( | |||||
| ~x, ~y, | |||||
| "1", "a", | |||||
| "2", "b" | |||||
| y <- data_frame( | |||||
| x = c(1, 2), | |||||
| y = c("a", "b") | |||||
| ) | ) | ||||
| animate_union(x, y, export = "first") | animate_union(x, y, export = "first") | ||||
| ``` r | ``` r | ||||
| x | x | ||||
| #> # A tibble: 3 x 2 | #> # A tibble: 3 x 2 | ||||
| #> x y | |||||
| #> <chr> <chr> | |||||
| #> 1 1 a | |||||
| #> 2 1 b | |||||
| #> 3 2 a | |||||
| #> x y | |||||
| #> <dbl> <chr> | |||||
| #> 1 1 a | |||||
| #> 2 1 b | |||||
| #> 3 2 a | |||||
| y | y | ||||
| #> # A tibble: 2 x 2 | #> # A tibble: 2 x 2 | ||||
| #> x y | |||||
| #> <chr> <chr> | |||||
| #> 1 1 a | |||||
| #> 2 2 b | |||||
| #> x y | |||||
| #> <dbl> <chr> | |||||
| #> 1 1 a | |||||
| #> 2 2 b | |||||
| ``` | ``` | ||||
| ### Union | ### Union | ||||
| ``` r | ``` r | ||||
| union(x, y) | union(x, y) | ||||
| #> # A tibble: 4 x 2 | #> # A tibble: 4 x 2 | ||||
| #> x y | |||||
| #> <chr> <chr> | |||||
| #> 1 2 b | |||||
| #> 2 2 a | |||||
| #> 3 1 b | |||||
| #> 4 1 a | |||||
| #> x y | |||||
| #> <dbl> <chr> | |||||
| #> 1 2 b | |||||
| #> 2 2 a | |||||
| #> 3 1 b | |||||
| #> 4 1 a | |||||
| ``` | ``` | ||||
| ``` r | ``` r | ||||
| union(y, x) | union(y, x) | ||||
| #> # A tibble: 4 x 2 | #> # A tibble: 4 x 2 | ||||
| #> x y | |||||
| #> <chr> <chr> | |||||
| #> 1 2 a | |||||
| #> 2 1 b | |||||
| #> 3 2 b | |||||
| #> 4 1 a | |||||
| #> x y | |||||
| #> <dbl> <chr> | |||||
| #> 1 2 a | |||||
| #> 2 1 b | |||||
| #> 3 2 b | |||||
| #> 4 1 a | |||||
| ``` | ``` | ||||
| ### Union All | ### Union All | ||||
| ``` r | ``` r | ||||
| union_all(x, y) | union_all(x, y) | ||||
| #> # A tibble: 5 x 2 | #> # A tibble: 5 x 2 | ||||
| #> x y | |||||
| #> <chr> <chr> | |||||
| #> 1 1 a | |||||
| #> 2 1 b | |||||
| #> 3 2 a | |||||
| #> 4 1 a | |||||
| #> 5 2 b | |||||
| #> x y | |||||
| #> <dbl> <chr> | |||||
| #> 1 1 a | |||||
| #> 2 1 b | |||||
| #> 3 2 a | |||||
| #> 4 1 a | |||||
| #> 5 2 b | |||||
| ``` | ``` | ||||
| ### Intersection | ### Intersection | ||||
| ``` r | ``` r | ||||
| intersect(x, y) | intersect(x, y) | ||||
| #> # A tibble: 1 x 2 | #> # A tibble: 1 x 2 | ||||
| #> x y | |||||
| #> <chr> <chr> | |||||
| #> 1 1 a | |||||
| #> x y | |||||
| #> <dbl> <chr> | |||||
| #> 1 1 a | |||||
| ``` | ``` | ||||
| ### Set Difference | ### Set Difference | ||||
| ``` r | ``` r | ||||
| setdiff(x, y) | setdiff(x, y) | ||||
| #> # A tibble: 2 x 2 | #> # A tibble: 2 x 2 | ||||
| #> x y | |||||
| #> <chr> <chr> | |||||
| #> 1 1 b | |||||
| #> 2 2 a | |||||
| #> x y | |||||
| #> <dbl> <chr> | |||||
| #> 1 1 b | |||||
| #> 2 2 a | |||||
| ``` | ``` | ||||
| ``` r | ``` r | ||||
| setdiff(y, x) | setdiff(y, x) | ||||
| #> # A tibble: 1 x 2 | #> # A tibble: 1 x 2 | ||||
| #> x y | |||||
| #> <chr> <chr> | |||||
| #> 1 2 b | |||||
| #> x y | |||||
| #> <dbl> <chr> | |||||
| #> 1 2 b | |||||
| ``` | ``` | ||||
| ## Tidy Data and `gather()`, `spread()` functionality | ## Tidy Data and `gather()`, `spread()` functionality | ||||
| [Tidy data](http://r4ds.had.co.nz/tidy-data.html#tidy-data-1) follows | |||||
| the following three rules: | |||||
| 1. Each variable has its own column. | |||||
| 2. Each observation has its own row. | |||||
| 3. Each value has its own cell. | |||||
| Many of the tools in the [tidyverse](https://tidyverse.org) expect data | |||||
| to be formatted as a tidy dataset and the | |||||
| [tidyr](https://tidyr.tidyverse.org) package provides functions to help | |||||
| you organize your data into tidy data. | |||||
| ``` r | ``` r | ||||
| long <- data_frame( | long <- data_frame( | ||||
| year = c(2010, 2011, 2010, 2011, 2010, 2011), | year = c(2010, 2011, 2010, 2011, 2010, 2011), |