-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgganimate_tut.Rmd
59 lines (45 loc) · 921 Bytes
/
gganimate_tut.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
---
title: "R Notebook"
output: html_notebook
---
# Prerequisities
```{r}
library(ggplot2)
library(gganimate)
theme_set(theme_bw())
```
# Demo dataset
```{r}
library(gapminder)
head(gapminder)
```
# Static plot
```{r}
p <- ggplot(
gapminder,
aes(x = gdpPercap, y=lifeExp, size = pop, colour = country)
) +
geom_point(show.legend = FALSE, alpha = 0.7) +
scale_color_viridis_d() +
scale_size(range = c(2, 12)) +
scale_x_log10() +
labs(x = "GDP per capita", y = "Life expectancy")
p
```
# Transition through distinc states in time
```{r}
p + transition_time(year) +
labs(title = "Year: {frame_time}")
```
# Create facets by continent:
```{r}
p + facet_wrap(~continent) +
transition_time(year) +
labs(title = "Year: {frame_time}")
```
# Let the view follow the data in each frame
```{r}
p + transition_time(year) +
labs(title = "Year: {frame_time}") +
view_follow(fixed_y = TRUE)
```