R语言绘制gif动图

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')#保存文件

在这里插入图片描述
如果有问题请在评论区回复

猜你喜欢

转载自blog.csdn.net/qq_54423921/article/details/125848572