分享

animation包画简单的动态图

 萌小芊 2018-04-12

    谢益辉大神写的animation包真的是很好玩。写一个循环再用animation包里面的saveGIF函数连接就可以弄出gif。前期准备需要imageMagick软件,在后面的代码convert=shQuote()会用到covert.exe的路径。

library(animation)
ani.options(interval = 0.1, nmax = 150,convert=shQuote(“D:\ImageMagick-7.0.7-Q16\convert.exe”))
saveGIF(brownian.motion(pch = 21,cex = 5,col = “red”, bg = “yellow”),
main = “Demonstration of Brownian Motion”)     


library(lattice)

对于lattice或是ggplot2绘图命令,最后一定要使用print,不然出不了图

saveGIF(
for (i in seq(0,360,by=5)) {
p <- wireframe(volcano,="" shade="">
aspect = c(61/87, 0.4),
light.source = c(10,0,10),
screen = list(z = i, x = -60))
print(p)

})

#气泡图

library(ggplot2)

#数据要求有三个数值型变量,x轴&y轴&气泡大小。

#另外两个最好是分类变量,一个是颜色,一个是i。

bubble<>

bubble<>

bubble<>

bubble$month<>

bubble$time<>

ani.options(interval = 0.5#控制播放速度,

            convert=shQuote('D:\\ImageMagick-7.0.7-Q16\\convert.exe'))

saveGIF(

for(i in 0:23){

  bub<>

  p<>

    geom_point(aes(col=month,size=O3))+ylim(0,200)+xlim(0,200)+

    annotate('text',x=200,y=200,label=i,col='gray')+

    theme(panel.grid.major.x=element_blank(),panel.grid.major.y = element_blank())

  print(p)

})


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多