我有一个包含经纬度坐标的数据集。目前,我可以使用ggmap和geom_path在地图上可视化轨迹。这个方法运行得很好。现在我想要将轨迹动画化,每10秒钟填充路径的一部分以呈现彩色效果,这是一种轨迹模拟。我尝试了animation包,但是只得到了一个空白的gif文件。我也尝试了Sys.sleep()函数,但它已经显示了整条轨迹。以下是用于坐标的样本数据集“temp”:
10.16530167 54.32216667
10.16530167 54.32216667
10.16529833 54.32216833
10.165295 54.32217
10.16529333 54.32217167
10.16529167 54.32217167
10.16529167 54.32217167
10.16529333 54.32217167
10.165295 54.32217
10.165295 54.32217
10.165295 54.32217167
10.16529333 54.32217
10.16528833 54.32217
10.16527833 54.32216667
10.16527167 54.32216
10.165265 54.32215667
所以,通过以下代码我可以可视化轨迹。这个运行良好:
require(ggmap)
require(mapproj)
ggmap(m)+geom_path(data=track_df, aes(x=temp$GPS_x,
y=temp$GPS_y),colour="red",size=1,lineend="round")
“track_df”包含每个点的时间和日期等数据。因此,我尝试使用“animation”包来获取我的模拟的.*gif文件,但在运行代码后,“ImageMagic”或“GraphicsMagic”显示输出文件,只有白屏,没有任何动画或图像。我正在执行以下代码:
require(animation)
npoints<- length(temp$GPS_x)
simulate <- function(){
for(i in 1:npoints){
ggmap(m)+geom_path(data=ricky_df, aes(x=temp$GPS_x[i],
y=temp$GPS_y[i]),colour="red",size=1,lineend="round")
}
}
oopt = ani.options(interval = 1, nmax = npoints)
saveMovie(simulate(),interval = 0.1, width = 580, height = 400)
我使用了来自这个网站的示例。
有人能给一个提示吗?
提前致谢!