This repository has been archived by the owner on May 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
transition_time_vs_transition_reveal.Rmd
157 lines (68 loc) · 2.4 KB
/
transition_time_vs_transition_reveal.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
title: "Difference between transition_time and transition_reveal"
author: "Robbie Bonelli"
date: "23/11/2018"
output: github_document
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE,echo=F}
library(ggplot2)
library(devtools)
library(dplyr)
library(gganimate)
#install_github("ropenscilabs/ozbabynames")
library(ozbabynames)
author_names <- c("Robin", "Robert", "Mitchell", "Nicholas", "Jessie", "Jessica")
dat <- ozbabynames %>%
filter(name %in% author_names) %>%
count(name,year, wt = count)
```
**Build the plot**
```{r}
p1 <- ggplot(aes(x = year,
y = n,
group = name),data=dat) +
geom_label(aes(label = name,fill = name),colour = "white", size = 10) +
theme_bw() +
theme(panel.grid = element_blank(),
legend.position = "none",
title = element_text(colour = "purple",
size = 20,
face = "bold")
) +
scale_y_log10(labels = scales::comma)
```
# `transition_time()` leaves a lot of "dirt" behind
```{r}
p <- p1+transition_time(time = year)
animate(p,nframes = 50)
```
### This can be solved by increasing the number of frames (possibly that's why the default is 100 frames)
```{r}
animate(p,nframes = 100)
```
# `tansition_reveal()` does not leave anything behind, even with a low number of frames
```{r}
p <- p1+transition_reveal(id = name, along = year)
animate(p,nframes = 50)
```
# `tansition_reveal()` can track down the trajctory with a line
In contrast, `transition_time()` will return oy's of warning error. It is probably because transition time is meant to show ony one data point per id (??)
```{r}
p2 <- p1 + geom_line(aes(colour = name),size = 1, linetype = "dotted")
p <- p2 + transition_reveal(id = name, along = year)
animate(p,nframes = 50)
```
# `tansition_reveal()` and `tansition_time()` need a different parameter that needs to be passed for the label of the frame.
### **frame_along** for `tansition_reveal()` and **frame_time** for `transition_time()` and
```{r}
p2 <- p1 + labs( title = "number of bubs dubbed in {frame_along} ", y = "n babies" )
p <- p2 + transition_reveal(id = name, along = year)
animate(p,nframes = 50)
```
```{r}
p2 <- p1 + labs( title = "number of bubs dubbed in {frame_time} ", y = "n babies" )
p <- p2 + transition_time(time = year)
animate(p,nframes = 50)
```