forked from R-tutorials/tidy-animated-verbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
00_base_set.R
50 lines (39 loc) · 1.12 KB
/
00_base_set.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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)