gapminder是我们要用到的数据,用gganimate来绘制gif动图
install.packages("gapminder")
install.packages("gganimate")
library(gapminder)
library(gganimate)
ggplot(gapminder,aes(gdpPercap,lifeExp,size=pop,colour=continent))+
geom_point(alpha=0.7,show.legend = F)+#设置透明度
scale_x_log10()+#对y取lg的对数
scale_size(range=c(2,12))+
facet_wrap(~continent)+#图形分面
#这是制作动画的部分
transition_time(year)+
labs(title="Year:{frame_time}",x="GDP per capita",y="life expecttancy")+
ease_aes("linear")
anim_save('123.gif')#保存文件
如果有问题请在评论区回复