谢益辉大神写的animation包真的是很好玩。写一个循环再用animation包里面的saveGIF函数连接就可以弄出gif。前期准备需要imageMagick软件,在后面的代码convert=shQuote()会用到covert.exe的路径。 library(animation) library(lattice) 对于lattice或是ggplot2绘图命令,最后一定要使用print,不然出不了图saveGIF( }) #气泡图 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) }) |
|