美文网首页
R可视化:动态图生成方法

R可视化:动态图生成方法

作者: 生信学习者2 | 来源:发表于2020-10-08 00:10 被阅读0次

动态图生成方法

静态图有时候无法完整表现数据的动态变化过程,现有R包ImageMagick可以生成动态gif图,方便数据分析师查看数据变化过程。更多知识分享请到 https://zouhua.top/

准备包

  • ImageMagick :产生动画
install.packages("installr")
installr::install.ImageMagick("http://www.imagemagick.org/script/download.php")
  • gganimate:制作动画,可以映射
install.packages("devtools")
devtools::install_github("dgrtwo/gganimate")
install.packages("animation")

运行

library(gapminder)
library(gganimate)
library(animation)
library(ggplot2)

p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size=pop,              color=continent,frame=year))+
     geom_point()+
     scale_x_log10()
magickPath <- shortPathName("C:\\Program Files\\ImageMagick-7.0.7-Q16\\magick.exe")    # 设置路径
ani.options(convert=magickPath)  # 设置convert参数

gganimate(p, "out.gif") # 生成且保留gif

总结

1. c:\program 路径无法找到:环境变量设置

Sys.setenv(PATH = paste("C:/Program Files/ImageMagick-7.0.7-Q16/bin",
 Sys.getenv("PATH"), sep = ";"))

2. ImageMagick旧版本的convert不可用(将png转成gif的工具),使用谢大神的新版本animation

devtools::install_github("yihui/animation").

参考

  1. 博客
  2. 缺失convert.exe
  3. 新版本convert
  4. c:\program路径找不到
  5. R语言中文社区

参考文章如引起任何侵权问题,可以与我联系,谢谢。

相关文章

网友评论

      本文标题:R可视化:动态图生成方法

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