【发布时间】:2014-02-21 14:47:36
【问题描述】:
我有 10 个纬度和经度点。使用下面的代码,我可以绘制坐标,按箭头顺序绘制箭头,并输出一个显示导航顺序的 gif 文件。
到目前为止,我只能使用 plot {graphics} 函数来做到这一点。因为箭头 {graphics} 和 saveGIF{animation} 似乎只适用于绘图功能。我想知道这是否可能是一个更合适的库,例如 ggmap(编辑:我误说 ggplot)、googleVis 等。
library(graphics)
library(animation)
lat <- c(34.083398,34.072467,34.030237,34.597334,34.587142,34.488386,33.443484,33.946902,33.062739,32.273711,32.272611)
lon <- c(-107.907107,-106.893156,-107.971542,-105.225107,-105.13397,-103.196355,-104.52479,-103.655698,-106.0156,-107.71744,-107.713977)
coords = data.frame(lat,lon)
x <- coords$lat ; y <- coords$lon
s <- seq(length(x)-1) # one shorter than data
saveGIF({
for(s in 1:length(x)){
plot(x,y)
arrows(x[s], y[s], x[s+1], y[s+1], col = 1:s)
}
})
【问题讨论】:
标签: r animation plot maps coordinates