-
Notifications
You must be signed in to change notification settings - Fork 0
/
animations.Rmd
68 lines (59 loc) · 2.14 KB
/
animations.Rmd
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
title: "Animations"
output: html_notebook
---
#### animations
```{r}
all_dat <- sim_data %>%
filter(term=="x1") #%>%
# mutate(time = as.factor(n) %>% as.numeric)
sim_data %>%
filter(term=="x1") %>%
mutate(time = as.factor(n) %>% as.numeric) %>%
ggplot(aes(cors, statistic, colour = n)) + # draw the original data series with grey
geom_smooth(data = all_dat, aes(cors, statistic, group = n), colour = alpha("grey", 0.4), size = 0.8, se = F) +
geom_smooth(method = "loess", se = F, size = 1, alpha = 0.8) +
xlab("Correlation") + labs(y = expression("t-statistic~(~x[1]~)")) +
theme_hc() + scale_color_viridis(direction = -1
# limits = c(5, 3.5) * 1000,
# breaks = c(0.1, 1.3, 2.5) * 1000,
# labels = c("50", "1300", "3000")
) +
# colourise only the filtered data
# geom_smooth(aes(idx, value, colour = type), data = d_filtered) +
geom_text(aes(x = .85, y = 13, label = paste0("Sample Size = ", n))) +
# Here comes the gganimate code
transition_time(
time
) +
enter_fade() +
exit_fade() +
ease_aes('sine-in-out')
all_dat <- sim_data %>%
filter(term=="x1") %>%
filter(n>200)
sim_data %>%
filter(term=="x1") %>%
filter(n>200) %>%
mutate(time = as.factor(n) %>% as.numeric) %>%
ggplot(aes(cors, estimate, colour = n)) + # draw the original data series with grey
geom_line(data = all_dat, aes(cors, estimate, group = n), colour = alpha("grey", 0.4), size = 0.8) +
geom_line(method = "loess", size = 1, alpha = 0.8) +
xlab("Correlation") + labs(y = expression("t-statistic~(~x[1]~)")) +
theme_hc() + scale_color_viridis(direction = -1
# limits = c(5, 3.5) * 1000,
# breaks = c(0.1, 1.3, 2.5) * 1000,
# labels = c("50", "1300", "3000")
) +
# colourise only the filtered data
# geom_smooth(aes(idx, value, colour = type), data = d_filtered) +
geom_text(aes(x = .15, y = 1.75, label = paste0("Sample Size = ", n))) +
# Here comes the gganimate code
transition_time(
time
) +
enter_fade() +
exit_fade() +
ease_aes('sine-in-out')
anim_save(filename = "wiggly.gif")
```