2015-04-04 60 views
0

我已经得到了我使用的地图和岩石圈的功能,看起来像一个航空地图内置的地图。但是,我想添加箭头来显示地图中“路线”的方向。您可以在下面看到我的当前工作代码(基于来自FlowingData的神奇教程)。我已经尝试过使用箭头函数代替线条函数,但我不确定如何使箭头与地圈曲线一起走,或者确保箭头沿着线条间隔,以便它们看起来像这样:如何在R中的地图上添加方向箭头?

- > - > - >

我难以置信的新R,所以任何和所有帮助将不胜感激。提前致谢。

library(maps) 
library(geosphere) 
read.csv("http://marsiccr.github.io/Data/airports.csv", header=TRUE, as.is=TRUE) -> airports 
read.csv("http://marsiccr.github.io/Data/leaders.csv", header=TRUE, as.is=TRUE) -> flights 
pal <- colorRampPalette(c("#f2f2f2", "blue")) 
colors <- pal(100) 
colleges<-NULL 
colleges$name <- airports$insname 
colleges$long <- airports$long 
colleges$lat <- airports$lat 
colleges 
map("state") 
map("state", col="#f2f2f2", fill=TRUE, bg="white", lwd=0.25) 
fsub <- flights[flights$type == "aau",] 
fsub <- fsub[order(fsub$cnt),] 
maxcnt <- max(fsub$cnt) 
for (j in 1:length(fsub$type)) { 
air1 <- airports[airports$unitid == fsub[j,]$school1,] 
air2 <- airports[airports$unitid == fsub[j,]$school2,] 
inter <- gcIntermediate(c(air1[1,]$long, air1[1,]$lat), c(air2[1,]$long, air2[1,]$lat), n=100, addStartEnd=TRUE) 
colindex <- round((fsub[j,]$cnt/maxcnt) * length(colors)) 

lines(inter, col=colors[colindex], lwd=0.8) 
} 

回答

0

滑倒这个代码进入for循环刚过inter<-让我箭头(和一些警告)

tinter <- tail(inter,2) 
arrows(tinter[1,1], tinter[1,2], tinter[2,1], tinter[2,2]) 

enter image description here

显然有一些调整来完成。有关全部选项,请参阅?arrows。您还可以使用inter矩阵中的倒数第二个(或倒数第五个?)点。您可能也只想为选定的路线输入箭头。

相关问题