美文网首页
使用R语言制作动画

使用R语言制作动画

作者: 费歇尔喵 | 来源:发表于2018-12-04 15:33 被阅读0次

R制作动画的本质,是将一系列的图片,合成一张gif格式的图片

可以举个简单的例子:

png(file="example%02d.png", width=480, height=480)
par(bg="grey")
  for (i in c(10:1, "G0!")){
    plot.new()
    text(.5, .5, i, cex = 6 )
  }
dev.off()

system("convert -delay 20 *.png animated_count_down.gif")
file.remove(list.files(pattern=".png"))

上面的代码,首先绘制了11张png格式的图片,之后,通过调用系统 ImageMagick工具包,将png格式转换成gif格式的图片

test.gif

除此之外,也有工具包可以直接依据ggplot2生成的对象,构建动态图,比如gganimate

# Get data:
library(gapminder)

# Charge libraries:
library(ggplot2)
#devtools::install_github("dgrtwo/gganimate")
library(gganimate)
 
# Make a ggplot, but add frame=year: one image per year
p<- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
  geom_point() +
  scale_x_log10() +
  theme_bw()
 
# Make the animation!ç
gganimate(p)
 
# Save it to Gif
gganimate(p, "271_gganimate.gif")

需要注意的是,gganimate工具包,在制作动画过程中,依然需要调用ImageMagick软件。

271_gganimate.gif

相关文章

  • 使用R语言制作动画

    R制作动画的本质,是将一系列的图片,合成一张gif格式的图片 可以举个简单的例子: 上面的代码,首先绘制了11张p...

  • 3D轨迹动画 R语言rayshaderanimate包

    video_animation3D轨迹动画 R语言rayshaderanimate包R语言读取gpx文件

  • R语言rayrender包,render_animation渲染

    R语言rayrender包,render_animation渲染动画

  • H5制作软件Hype — 物理量的介绍与使用

    在Hype中制作动画效果,除了使用录制关键帧动画以外,还可以使用它的物理量功能来进行一些动画的制作。Hype可让使...

  • R语言学习

    R语言基础入门 良好的R使用习惯 R支持中文,但不好!建议用全英文环境。 R语言具有严格的符号与语法控制,建议使用...

  • R 语言--日期值的输入

    学习R语言,很多人都推荐使用图灵程序设计丛书中的"R in Action"-《R语言实战》作为R语言学习的入门书籍...

  • 学习小组Day4笔记-Herobrine

    R语言入门 R和Rstudio RStudio是R的一个集成开发环境。下载安装好R和Rstudio,需要使用R语言...

  • R基础快速入门(2)

    文集地址 R语言快速入门 R语言变量 R语言中的变量可以存储原子向量,原子向量组或许多R对象的组合 注意:使用ca...

  • jQuery |动画

    利用jQuery ,自己动手做动画。使用jQuery 的animate() 方法,制作动画。 语法: $(sele...

  • R语言学习记录

    如何理解AUC R语言 apply函数家族详解 R语言资料从Github上安装R包 Windows下使用insta...

网友评论

      本文标题:使用R语言制作动画

      本文链接:https://www.haomeiwen.com/subject/hczmcqtx.html