-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathData_Animation.Rmd
94 lines (70 loc) · 2.21 KB
/
Data_Animation.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
## Data Animation
{width=1in}
{width=1in}
{width=1.5in}
### gganimate
The datasauRus
{width=1in}
- Use `datasauRus`, `ggplot2` and `gganimate` [@R-datasauRus, @R-ggplot2, @R-gganimate]
### gganimate: Datasaurus Dozen
{width=1in}
- Use `datasauRus`, `ggplot2` and `gganimate` [@R-datasauRus, @R-ggplot2, @R-gganimate].
We will use the `datasaurus_dozen` data for this example [@R-datasauRus]. First we should get a sense of the contents of this data set.
```{r data_datasaurus_dozen-check, exercise=TRUE}
# Check the names for the `datasaurus_dozen` data
```
```{r data_datasaurus_dozen-check-solution}
names(datasaurus_dozen)
```
Create an animation (depending on your server this may work better on your local machine).
```{r animate_datasaurus_dozen, exercise=TRUE}
# Change the 'ease_aes()' option from default 'linear'
# to 'cubic-in-out' for a smoother appearance
ggplot(datasaurus_dozen,
aes(x = x,
y = y))+
geom_point()+
theme_minimal() +
transition_states(states = dataset) +
ease_aes()
```
```{r animate_datasaurus_dozen-solution}
ggplot(datasaurus_dozen,
aes(x = x,
y = y))+
geom_point()+
theme_minimal() +
transition_states(states = dataset) +
ease_aes('cubic-in-out')
```
### gganimate: diamonds carat
{width=1in}
- Use `tidyverse`, `ggplot2` and `gganimate` [@R-tidyverse, @R-ggplot2, @R-gganimate].
```{r animate_diamonds, exercise=TRUE}
# Change our 'dsmall' selection
# of diamonds data to 100 observations
dsmall <- top_n(diamonds,
n = 40)
ggplot(data = dsmall,
aes(x = carat,
y = price,
color = color)) +
geom_line() +
transition_reveal(carat) +
ease_aes()
```
```{r animate_diamonds-solution}
dsmall <- top_n(diamonds,
n = 100)
ggplot(data = dsmall,
aes(x = carat,
y = price,
color = color)) +
geom_line() +
transition_reveal(carat) +
ease_aes()
```
You can add a label that follow the transitions by adding `labs` options:
```
+ labs(title = 'Diamond carat: {frame_along}')
```