R gganimate不平滑动画
几天来,我一直在试图弄清楚这一点,但我无法理解我遗漏了什么。gganimate似乎没有在帧之间添加任何过渡 我在用电脑。根据这一点,我多年来与获奖国家建立了一个数据框架。我有每年的累计胜利数,并加上当年每个国家的排名。共有106个版本,从1年到106年,以及106年(从1903年到2019年,由于WWs的原因有一些空白) 编辑:可用CSV格式的数据集:R gganimate不平滑动画,r,ggplot2,gif,gganimate,R,Ggplot2,Gif,Gganimate,几天来,我一直在试图弄清楚这一点,但我无法理解我遗漏了什么。gganimate似乎没有在帧之间添加任何过渡 我在用电脑。根据这一点,我多年来与获奖国家建立了一个数据框架。我有每年的累计胜利数,并加上当年每个国家的排名。共有106个版本,从1年到106年,以及106年(从1903年到2019年,由于WWs的原因有一些空白) 编辑:可用CSV格式的数据集: >领先(排名第20位) #一个tibble:20x5 #组别:年份[2] 国籍胜利版年度排名 1法国1 1903 1 2卢森堡0 1 1903
>领先(排名第20位)
#一个tibble:20x5
#组别:年份[2]
国籍胜利版年度排名
1法国1 1903 1
2卢森堡0 1 1903 2
3比利时01 1903 3
4意大利01 1903 4
5瑞士01 1903 5
6西班牙01 1903 6
7荷兰0 1 1903 7
8美国0 1 1903 8
9爱尔兰0 1 1903 9
10丹麦01 1903 10
11德国01 1903 11
12澳大利亚01 1903 12
13大不列颠0 1 1903 13
14哥伦比亚0 1 1903 14
15法国2 1904 1
16卢森堡0 2 1904 2
17比利时0 2 1904 3
18意大利02 1904 4
19瑞士0 2 1904 5
20西班牙02 1904 6
>尾巴(种族图排名第20)
#一个tibble:20x5
#组别:年份[2]
国籍胜利版年度排名
1瑞士2 105 2018 9
2澳大利亚1 105 2018 10
3丹麦1 105 2018 11
4德国1 105 2018 12
5爱尔兰1 105 2018 13
6哥伦比亚0 105 2018 14
7法国36 106 2019 1
8比利时18 106 2019 2
9西班牙12 106 2019 3
10意大利10 106 2019 4
11美国10 106 2019 5
12大不列颠6 106 2019 6
13卢森堡5 106 2019 7
14荷兰2 106 2019 8
15瑞士2 106 2019 9
16澳大利亚1 106 2019 10
17哥伦比亚1 106 2019 11
18丹麦1 106 2019 12
19德国1 106 2019 13
20爱尔兰1 106 2019 14
我制作了这个情节,效果很好,只是效果不太好。我已经尝试过改变持续时间、帧数和fps的数量,但它确实改变了很多。我尝试添加“ease_aes()”,但没有产生任何变化。我错过了什么
动画排名%
ggplot(aes(xmin=0,xmax=n.胜利,ymin=rank-.5,ymax=rank+0.5,y=rank))+
几何校正(fill=“black”,color=“black”,size=1.05)+
标度x连续(极限=c(-15,40),中断=c(序号(0,40,by=5)))+
#为每个国家/地区添加标签
geom_文本(aes(标签=国籍,x=(-2.5),hjust=“右”),大小=6,字体脸=“粗体”)+
#添加带有年份的标签
几何图形文本(aes(标签=年份,x=35,y=13.5,尺寸=15)+
#为每个国家/地区添加获胜次数(如果超过0)
geom_文本(数据=比赛图表排名%>%过滤器(n.胜利>0),
aes(标签=n.victories,x=n.victories-0.75,y=rank),color=“白色”,fontface=“粗体”)+
#颠倒比例,在顶部显示最高的胜利
比例尺y反方向()+
#添加标签
实验室(title=“按国家划分的获胜次数”,
x=“获胜次数”,y=“”)+
#选择主题
主题_void()+
#动画代码
#逐年分组
不良事件(组=年)+
#按时间应用转换
过渡时间(年)+
#应用ease_eas()
放松
#设置动画常规选项
选项(gganimate.nframes=100,gganimate.fps=20)
#设置动画和其他选项
设置动画(动画排名,结束暂停=10,持续时间=15)
我也有同样的问题。我对你的解决方案很感兴趣。
> head(race_chart_ranked, 20)
# A tibble: 20 x 5
# Groups: year [2]
nationality n.victories edition year rank
<chr> <int> <dbl> <dbl> <int>
1 France 1 1 1903 1
2 Luxembourg 0 1 1903 2
3 Belgium 0 1 1903 3
4 Italy 0 1 1903 4
5 Switzerland 0 1 1903 5
6 Spain 0 1 1903 6
7 Netherlands 0 1 1903 7
8 United States 0 1 1903 8
9 Ireland 0 1 1903 9
10 Denmark 0 1 1903 10
11 Germany 0 1 1903 11
12 Australia 0 1 1903 12
13 Great Britain 0 1 1903 13
14 Colombia 0 1 1903 14
15 France 2 2 1904 1
16 Luxembourg 0 2 1904 2
17 Belgium 0 2 1904 3
18 Italy 0 2 1904 4
19 Switzerland 0 2 1904 5
20 Spain 0 2 1904 6
> tail(race_chart_ranked, 20)
# A tibble: 20 x 5
# Groups: year [2]
nationality n.victories edition year rank
<chr> <int> <dbl> <dbl> <int>
1 Switzerland 2 105 2018 9
2 Australia 1 105 2018 10
3 Denmark 1 105 2018 11
4 Germany 1 105 2018 12
5 Ireland 1 105 2018 13
6 Colombia 0 105 2018 14
7 France 36 106 2019 1
8 Belgium 18 106 2019 2
9 Spain 12 106 2019 3
10 Italy 10 106 2019 4
11 United States 10 106 2019 5
12 Great Britain 6 106 2019 6
13 Luxembourg 5 106 2019 7
14 Netherlands 2 106 2019 8
15 Switzerland 2 106 2019 9
16 Australia 1 106 2019 10
17 Colombia 1 106 2019 11
18 Denmark 1 106 2019 12
19 Germany 1 106 2019 13
20 Ireland 1 106 2019 14
animation_ranked <- race_chart_ranked %>%
ggplot(aes(xmin = 0, xmax = n.victories, ymin=rank-.5, ymax=rank+0.5, y=rank)) +
geom_rect(fill = "black", color="black", size=1.05) +
scale_x_continuous(limits=c(-15, 40), breaks=c(seq(0, 40, by=5))) +
# Add labels to each country
geom_text(aes(label=nationality, x=(-2.5), hjust="right"), size = 6, fontface="bold") +
# Add a label with the year
geom_text(aes(label=year, x=35, y=13.5), size=15) +
# Add number of victories (if more than 0) for each country
geom_text(data=race_chart_ranked %>% filter(n.victories > 0),
aes(label=n.victories, x=n.victories-0.75, y=rank), color="white", fontface="bold") +
# Reverse the scale to show the highest victories on top
scale_y_reverse() +
# Add labels
labs(title = "Number of victories by country",
x = "Number of victories", y = "") +
# Choose theme
theme_void() +
# ANIMATION CODE
# Group by year
aes(group = year) +
# Apply transition by time
transition_time(year) +
# Apply ease_eas()
ease_aes()
# Set animation general options
options(gganimate.nframes = 100, gganimate.fps = 20)
# Animate and other options
animate(animation_ranked, end_pause=10, duration = 15)