forked from perlatex/R_for_Data_Science
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ggplot2_gganimate.Rmd
845 lines (637 loc) · 18.9 KB
/
ggplot2_gganimate.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
# ggplot2之让你的数据骚动起来 {#ggplot2-gganimate}
这节课,我们讲如何让我们的图动起来。(因为渲染需要花费很长时间,所以文档中的动图代码都没有执行。)
## 为什么要使用动图
- 改进了图形在时间上和空间上的重新定位
- 传递更多信息
- 引人注意
## `gganimate`宏包
动图可以将其理解为多张静态图堆在一起,当然不是随意的堆放,而是按照一定的规则,比如按照时间的顺序,或者类别的顺序。一般而言,动图制作包括两个步骤: 静态图制作及图形组装。静态图制作,前面几章我们讲过主要用ggplot2宏包实现;对于图形组装,需要用到今天我们要讲Thomas Lin Pedersen的`gganimate`宏包,来自同一工厂的产品,用起来自然是无缝衔接啦。
```{r ggplot2-gganimate-1, eval=FALSE}
install.packages("gganimate")
```
### 先来一张静态图
```{r ggplot2-gganimate-2, eval=FALSE}
library(tidyverse)
library(covdata) # remotes::install_github("kjhealy/covdata")
library(gganimate)
```
```{r ggplot2-gganimate-3, eval=FALSE}
covdata::covnat %>%
dplyr::filter(iso3 == "USA") %>%
dplyr::filter(cu_cases > 0) %>%
ggplot(aes(x = date, y = cases)) +
geom_path() +
labs(
title = "美国新冠肺炎累积确诊病例",
subtitle = "数据来源https://kjhealy.github.io/covdata/"
)
```
让它动起来,我们只需要增加一行代码!
``` {r, eval=FALSE}
covdata::covnat %>%
dplyr::filter(iso3 == "USA") %>%
dplyr::filter(cu_cases > 0) %>%
ggplot(aes(x = date, y = cases)) +
geom_path() +
labs(
title = "美国新冠肺炎累积确诊病例 {frame_along}",
subtitle = "数据来源https://kjhealy.github.io/covdata/"
) +
transition_reveal(along = date)
```
### 相对复杂点的例子
```{r ggplot2-gganimate-4, eval=FALSE}
library(datasauRus)
ggplot(datasaurus_dozen) +
aes(x, y, color = dataset) +
geom_point()
```
用分面展示
```{r ggplot2-gganimate-5, eval=FALSE}
ggplot(datasaurus_dozen) +
aes(x, y, color = dataset) +
geom_point() +
facet_wrap(~dataset)
```
可以用动图展示
```{r ggplot2-gganimate-6, eval=FALSE}
ggplot(datasaurus_dozen) +
aes(x, y, color = dataset) +
geom_point() +
transition_states(dataset, 3, 1) + # <<
labs(title = "Dataset: {closest_state}")
```
是不是很炫酷,下面我们就一个个讲解其中的函数。
## The grammar of animation
使用`gganimate`做动画,只需要掌握以下五类函数:
- `transition_*()`: 定义动画是根据哪个变量进行”动”,以及如何”动”
- `view_*()`: 定义坐标轴随数据变化.
- `shadow_*()`: 影子(旧数据的历史记忆)?定义点相继出现的方式.
- `enter_*()/exit_*()`: 定义新数据出现和旧数据退去的方式.
- `ease_aes()`: 美观定义,控制变化的节奏(如何让整个动画看起来更舒适).
下面通过案例依次讲解这些函数功能。
## 希望动画随哪个变量动起来
变量如何选择,这需要从变量类型和变量代表的信息来确定。
### transition_states
- `transition_states(states = )`, 这里的参数states往往带有分组信息,可以等价于静态图中的分面。
```{r ggplot2-gganimate-7, eval=FALSE}
diamonds %>%
ggplot(aes(carat, price)) +
geom_point()
```
```{r ggplot2-gganimate-8, eval=FALSE}
diamonds %>%
ggplot(aes(carat, price)) +
geom_point() +
facet_wrap(vars(color))
```
```{r ggplot2-gganimate-9, eval=FALSE}
diamonds %>%
ggplot(aes(carat, price)) +
geom_point() +
transition_states(states = color, transition_length = 3, state_length = 1)
```
### transition_time
- `transition_time(time = )`, 这里的time一般认为是**连续**的值,相比于`transition_states`,没有了`transtion_length`这个选项,是因为`transtion_length`默认为time. 事实上,`transition_time`是`transition_states`的一种特例,但其实也有分组的要求
```{r ggplot2-gganimate-10, eval=FALSE}
p <- gapminder::gapminder %>%
ggplot(aes(x = gdpPercap, y = lifeExp, size = pop, colour = country)) +
geom_point(alpha = 0.7, show.legend = FALSE) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
labs(
x = "GDP per capita",
y = "life expectancy"
)
p
```
```{r ggplot2-gganimate-11, eval=FALSE}
anim <- p +
transition_time(time = year) +
labs(title = "year: {frame_time}")
anim
```
### transition_reveal
- `transition_reveal(along = )`, along 这个词可以看出,它是按照某个变量**依次**显示的意思,比如顺着x轴显示
```{r ggplot2-gganimate-12, eval=FALSE}
ggplot(data = economics) +
aes(x = date, y = unemploy) +
geom_line()
```
```{r ggplot2-gganimate-13, eval=FALSE}
ggplot(economics) +
aes(x = date, y = unemploy) +
geom_line() +
transition_reveal(along = date) +
labs(title = "now is {frame_along}")
```
### transition_filter
- `transition_filter( 至少2个筛选条件,transition_length = , filter_length =)`, 动图将会在这些筛选条件对应的子图之间转换
```{r ggplot2-gganimate-14, eval=FALSE}
diamonds %>%
ggplot(aes(carat, price)) +
geom_point() +
transition_filter(
transition_length = 3,
filter_length = 1,
cut == "Ideal",
Deep = depth >= 60
)
```
### transition_layers
- `transition_layers()`: 依次显示每个图层
```{r ggplot2-gganimate-15, eval=FALSE}
mtcars %>%
ggplot(aes(mpg, disp)) +
geom_point() +
geom_smooth(colour = "grey", se = FALSE) +
geom_smooth(aes(colour = factor(gear))) +
transition_layers(
layer_length = 1, transition_length = 2,
from_blank = FALSE, keep_layers = c(Inf, 0, 0)
) +
enter_fade() +
exit_fade()
```
### 其他
- `transition_manual()`
- `transition_components()`
- `transition_events()`
## 希望坐标轴随数据动起来
动画过程中,绘图窗口怎么变化呢?
```{r views-tbl, echo=FALSE, eval=FALSE}
tribble(
~Function, ~Description,
"view_follow", "完全跟随当前数据的范围",
"view_step", "类似 view_follow, 除了过渡的时候要静止下下",
"view_step_manual", "类似 view_step, 除了需要手动定义坐标轴的范围",
"view_zoom", "与view_step一样, 但更变化过程更平滑",
"view_zoom_manual", "同上,除了需要手动定义坐标轴的范围"
)
```
### view_follow
```{r ggplot2-gganimate-16, eval=FALSE}
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_point() +
labs(title = "{closest_state}") +
transition_states(Species, transition_length = 4, state_length = 1) +
view_follow()
```
### 其它
- `view_step()`
- `view_step_manual()`
- `view_zoom()`
- `view_zoom_manual()`
## 希望动画有个记忆
- `shadow_wake(wake_length =, ) ` 旧数据消退时,制造点小小的尾迹的效果(wake除了叫醒,还有尾迹的意思,合起来就是记忆_尾迹)
- `shadow_trail(distance = 0.05)` 旧数据消退时,制造面包屑一样的残留痕迹(记忆_零星残留)
- `shadow_mark(past = TRUE, future = FALSE)` 将旧数据和新数据当作背景(记忆_标记)
### shadow_wake()
```{r ggplot2-gganimate-17, eval=FALSE}
p +
transition_time(time = year) +
labs(title = "year: {frame_time}") +
shadow_wake(wake_length = 0.1, alpha = FALSE)
```
```{r ggplot2-gganimate-18, eval=FALSE}
ggplot(iris, aes(Petal.Length, Sepal.Length)) +
geom_point(size = 2) +
labs(title = "{closest_state}") +
transition_states(Species, transition_length = 4, state_length = 1) +
shadow_wake(wake_length = 0.1)
```
### shadow_trail()
```{r ggplot2-gganimate-19, eval=FALSE}
p +
transition_time(time = year) +
labs(title = "year: {frame_time}") +
shadow_trail(distance = 0.1)
```
```{r ggplot2-gganimate-20, eval=FALSE}
ggplot(iris, aes(Petal.Length, Sepal.Length)) +
geom_point(size = 2) +
labs(title = "{closest_state}") +
transition_states(Species, transition_length = 4, state_length = 1) +
shadow_trail(distance = 0.1)
```
### shadow_mark()
```{r ggplot2-gganimate-21, eval=FALSE}
p +
transition_time(time = year) +
labs(title = "year: {frame_time}") +
shadow_mark(alpha = 0.3, size = 0.5)
```
```{r ggplot2-gganimate-22, eval=FALSE}
ggplot(airquality, aes(Day, Temp)) +
geom_line(color = "red", size = 1) +
transition_time(Month) +
shadow_mark(colour = "black", size = 0.75)
```
## 定义新数据出现和旧数据退去的方式
出现和退去的函数是成对的
```{r enter-exit-tbl, echo=FALSE, eval=FALSE}
tribble(
~Function, ~Description,
"enter_appear/exit_disappear", "突然出现,或者闪退",
"enter_fade/exit_fade", "使用透明度上的变化",
"enter_grow/exit_shrink", "使用大小上的变化",
"enter_recolour/exit_recolour", "使用颜色上的变化",
"enter_fly/exit_fly", "使用位置上飞来飞去的效果",
"enter_drift/exit_drift", "使用位置上漂移的效果",
"enter_reset/exit_reset", "使用清空之前的效果"
)
```
### enter/exit_fade()
透明度上的变化,我这里用柱状图展示,效果要明显一点。
```{r ggplot2-gganimate-23, eval=FALSE}
tibble(
x = month.name,
y = sample.int(12)
) %>%
ggplot(aes(x = x, y = y)) +
geom_col() +
theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)) +
transition_states(states = month.name)
```
```{r ggplot2-gganimate-24, eval=FALSE}
tibble(
x = month.name,
y = sample.int(12)
) %>%
ggplot(aes(x = x, y = y)) +
geom_col() +
theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)) +
transition_states(states = month.name) +
shadow_mark(past = TRUE) +
enter_fade()
```
```{r ggplot2-gganimate-25, eval=FALSE}
p +
transition_time(time = year) +
labs(title = "year: {frame_time}") +
enter_fade()
```
### enter_grow()/exit_shrink()
大小上的变化
```{r ggplot2-gganimate-26, eval=FALSE}
tibble(
x = month.name,
y = sample.int(12)
) %>%
ggplot(aes(x = x, y = y)) +
geom_col() +
theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)) +
transition_states(states = month.name) +
shadow_mark(past = TRUE) +
enter_grow()
```
```{r ggplot2-gganimate-27, eval=FALSE}
p +
transition_time(time = year) +
labs(title = "year: {frame_time}") +
enter_grow() +
enter_fade()
```
## 控制变化的节奏
控制数据点变化的快慢
```r
p + ease_aes({aesthetic} = {ease})
p + ease_aes(x = "cubic")
```
```{r ggplot2-gganimate-28, out.width='100%', fig.align='left'}
knitr::include_graphics("images/ease.png")
```
Source: https://easings.net/
看下面的案例:
```{r ggplot2-gganimate-29, eval=FALSE}
diamonds %>%
ggplot(aes(carat, price)) +
geom_point() +
transition_states(color, transition_length = 3, state_length = 1) +
ease_aes("cubic-in") # Change easing of all aesthetics
```
```{r ggplot2-gganimate-30, eval=FALSE}
diamonds %>%
ggplot(aes(carat, price)) +
geom_point() +
transition_states(color, transition_length = 3, state_length = 1) +
ease_aes(x = "elastic-in") # Only change `x` (others remain “linear”)
```
## 标签
我们可能需要在标题中加入每张动画的信息,常用罗列如下
```{r ggplot2-gganimate-31, eval=FALSE}
transition_states(states = ) +
labs(title = "previous is {previous_state},
current is {closest_state},
next is {next_state}")
transition_layers() +
labs(title = "previous is {previous_layers},
current is {closest_layers},
next is {next_layers}")
transition_time(time = ) +
labs(title = "now is {frame_time}")
transition_reveal(along = ) +
labs(title = "now is {frame_along}")
```
## 保存
### Renderer options
```{r renderer-tbl, echo=FALSE}
tibble::tribble(
~Function, ~Description,
"gifski_renderer", "Default, super fast gif renderer.",
"magick_renderer", "Somewhat slower gif renderer.",
"ffmpeg_renderer", "Uses ffmpeg to create a video from the animation.",
"av_renderer", "Uses the av package to create a video (using ffmpeg).",
"file_renderer", "Dumps a list of image frames from the animation.",
"sprite_renderer", "Creates a spritesheet from frames of the animation."
)
```
### 常用方法
一般用`anim_save()`保存为 gif 格式,方法类似`ggsave()`
```{r ggplot2-gganimate-32, eval=F}
animation_to_save <- diamonds %>%
ggplot(aes(carat, price)) +
geom_point() +
transition_states(color, transition_length = 3, state_length = 1) +
ease_aes("cubic-in")
anim_save("first_saved_animation.gif", animation = animation_to_save)
```
## 案例演示一
<!-- 这是网上有段时间比较火的racing_bar图 -->
<!-- ```{r} -->
<!-- ranked_by_year <- -->
<!-- gapminder %>% -->
<!-- select(country, pop, year, continent) %>% -->
<!-- group_by(year) %>% -->
<!-- arrange(year, desc(pop)) %>% -->
<!-- mutate(rank = 1:n()) %>% -->
<!-- filter(rank <= 10) -->
<!-- ``` -->
<!-- ```{r} -->
<!-- ranked_by_year %>% -->
<!-- ungroup() %>% -->
<!-- mutate(pop = pop / 1000000) %>% -->
<!-- ggplot(aes( -->
<!-- x = rank, -->
<!-- y = country, -->
<!-- group = country, -->
<!-- label = country, -->
<!-- fill = continent -->
<!-- )) + -->
<!-- geom_tile( -->
<!-- aes( -->
<!-- y = pop / 2, -->
<!-- height = pop, -->
<!-- width = 0.9, -->
<!-- fill = continent -->
<!-- ), -->
<!-- alpha = 0.8, -->
<!-- show.legend = F -->
<!-- ) + -->
<!-- geom_text(aes( -->
<!-- y = pop, -->
<!-- label = country, -->
<!-- color = ifelse(pop > 1100, "#ffffff", "#000000"), -->
<!-- hjust = ifelse(pop > 1100, 1, 0) -->
<!-- )) + -->
<!-- scale_x_reverse( -->
<!-- breaks = c(1:10), -->
<!-- label = c(1:10) -->
<!-- ) + -->
<!-- theme_minimal() + -->
<!-- coord_flip(clip = "off", expand = FALSE) + -->
<!-- labs( -->
<!-- title = "year {closest_state}", -->
<!-- x = "", -->
<!-- y = "Population (millions)", -->
<!-- caption = "Source: github/corydonbaylor" -->
<!-- ) + -->
<!-- transition_states(year, -->
<!-- transition_length = 4, -->
<!-- state_length = 1, -->
<!-- wrap = TRUE -->
<!-- ) + -->
<!-- ease_aes("cubic-in-out") -->
<!-- ``` -->
这是网上有段时间比较火的racing_bar图
```{r ggplot2-gganimate-33, eval=FALSE}
ranked_by_date <- covdata::covnat %>%
group_by(date) %>%
arrange(date, desc(cu_cases)) %>%
mutate(rank = 1:n()) %>%
filter(rank <= 10) %>%
ungroup()
```
```{r ggplot2-gganimate-34, eval=FALSE}
ranked_by_date %>%
filter(date >= "2020-05-01") %>%
ggplot(
aes(x = rank, y = cname, group = cname, fill = cname)
) +
geom_tile(
aes(
y = cu_cases / 2,
height = cu_cases,
width = 0.9
),
alpha = 0.8,
show.legend = F
) +
geom_text(aes(
y = cu_cases,
label = cname
),
show.legend = FALSE
) +
scale_x_reverse(
breaks = c(1:10),
label = c(1:10)
) +
theme_minimal() +
coord_flip(clip = "off", expand = FALSE) +
labs(
title = "日期: {closest_state}",
x = "",
caption = "Source: github/kjhealy/covdata"
) +
transition_states(date,
transition_length = 4,
state_length = 1,
wrap = TRUE
) +
ease_aes("cubic-in-out")
```
## 案例演示二
```{r ggplot2-gganimate-35, eval=FALSE}
bats <- readr::read_csv("./demo_data/bats-subset.csv") %>%
dplyr::mutate(id = factor(id))
```
```{r ggplot2-gganimate-36, eval=FALSE}
bats %>%
ggplot(aes(
x = longitude,
y = latitude,
group = id,
color = id
)) +
geom_point()
```
### 常规的方法
```{r ggplot2-gganimate-37, eval=FALSE}
bats %>%
ggplot(aes(
x = longitude,
y = latitude,
group = id,
color = id
)) +
geom_point() +
transition_time(time) +
shadow_mark(past = TRUE)
```
- geom_path()是按照数据点出现的先后顺序
- geom_line()是按照数据点在x轴的顺序
```{r ggplot2-gganimate-38, eval=FALSE}
bats %>%
ggplot(aes(
x = longitude,
y = latitude,
group = id,
color = id
)) +
geom_path() +
transition_time(time) +
shadow_mark(past = TRUE)
```
### 炫酷点的
<!-- 此时geom_path() + transition_reveal(time) = transition_time(time) -->
```{r ggplot2-gganimate-39, eval=FALSE}
bats %>%
dplyr::mutate(
image = "images/bat-cartoon.png"
) %>%
ggplot(aes(
x = longitude,
y = latitude,
group = id,
color = id
)) +
geom_path() +
ggimage::geom_image(aes(image = image), size = 0.1) +
transition_reveal(time)
```
## 案例演示三
全球R-Ladies组织,会议活动的情况,我们在地图上用动图展示
```{r ggplot2-gganimate-40, eval=FALSE}
rladies <- read_csv("./demo_data/rladies.csv")
rladies
```
这里需要一个地图,可以这样
```{r ggplot2-gganimate-41, eval=FALSE}
ggplot() +
ggplot2::borders("world", colour = "gray85", fill = "gray80") +
ggthemes::theme_map()
```
当然,最好是这样
```{r ggplot2-gganimate-42, eval=FALSE}
library(maps)
world <- map_data("world")
world_map <- ggplot() +
geom_polygon(data = world,
aes(x = long, y = lat, group = group),
color = "white", fill = "gray80"
) +
ggthemes::theme_map()
world_map
```
然后把点打上去
```{r ggplot2-gganimate-43, eval=FALSE}
world_map +
geom_point(
data = rladies,
aes(x = lon, y = lat, size = followers),
colour = "purple", alpha = .5
) +
scale_size_continuous(
range = c(1, 8),
breaks = c(250, 500, 750, 1000)
) +
labs(size = "Followers")
```
用动图展示(这种方法常用在流行病传播的展示上)
```{r ggplot2-gganimate-44, eval=FALSE}
world_map +
geom_point(aes(x = lon, y = lat, size = followers),
data = rladies,
colour = "purple", alpha = .5
) +
scale_size_continuous(
range = c(1, 8),
breaks = c(250, 500, 750, 1000)
) +
transition_states(created_at) +
shadow_mark(past = TRUE) +
labs(title = "Day: {closest_state}")
```
## 课后作业
### 作业1
把下图弄成你喜欢的样子
```{r ggplot2-gganimate-45, eval=FALSE}
library(gapminder)
theme_set(theme_bw())
ggplot(gapminder) +
aes(
x = gdpPercap, y = lifeExp,
size = pop, colour = country
) +
geom_point(show.legend = FALSE) +
scale_x_log10() +
scale_color_viridis_d() +
scale_size(range = c(2, 12)) +
labs(x = "GDP per capita", y = "Life expectancy") +
transition_time(year) +
labs(title = "Year: {frame_time}")
```
### 作业2
那请说说这以下三个的区别?
```{r ggplot2-gganimate-46, eval=FALSE}
bats %>%
dplyr::filter(id == 1) %>%
ggplot(
aes(
x = longitude,
y = latitude
)
) +
geom_point() +
transition_reveal(time) # <<
bats %>%
dplyr::filter(id == 1) %>%
ggplot(
aes(
x = longitude,
y = latitude
)
) +
geom_point() +
transition_states(time) # <<
bats %>%
dplyr::filter(id == 1) %>%
ggplot(
aes(
x = longitude,
y = latitude
)
) +
geom_point() +
transition_time(time) # <<
```
```{r ggplot2-gganimate-47, echo = F}
# remove the objects
# rm(list=ls())
#rm(anim, bats, p, ranked_by_date, rladies, world, world_map)
#rm(anim, bats, p, ranked_by_date, rladies)
```
```{r ggplot2-gganimate-48, echo = F, message = F, warning = F, results = "hide"}
pacman::p_unload(pacman::p_loaded(), character.only = TRUE)
```