1

I've got a map that I've built using the maps and geosphere packages that looks like an airline map. However, I'd like to add arrows to the lines to show the directions of the "routes" in my map. You can see my current working code below (based off of the fabulous tutorial from FlowingData). I've tried before to use the arrows function in lieu of the lines function, yet I'm not sure how to make the arrows go with the geosphere curve, or ensure that the arrows are spaced along the line so that they look like this:

-->-->-->

I'm incredibly new to R, so any and all assistance would be greatly appreciated. Thanks in advance.

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)
}
4

1 回答 1

0

inter<-在得到我的箭头(和一些警告)之后,将此代码滑入 for 循环

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

在此处输入图像描述

显然有一些调整要做。查看?arrows完整的选项。inter您还可以使用矩阵中倒数第二个(或倒数第五个?)点。您可能还只想为选定的路线添加箭头。

于 2015-04-04T19:59:45.463 回答