【发布时间】:2015-04-04 19:36:38
【问题描述】:
我有一张使用maps 和geosphere 包构建的地图,看起来像航空公司地图。但是,我想在线条上添加箭头以显示地图中“路线”的方向。您可以在下面看到我当前的工作代码(基于来自FlowingData 的精彩教程)。我之前尝试过使用箭头功能代替线条功能,但我不确定如何使箭头与地圈曲线一致,或者确保箭头沿线间隔开,以便它们看起来像这样:
-->-->-->
我对 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)
}
【问题讨论】:
-
代码中的 url 返回 404 not found,能否请您提供一个新的、可重现的示例?这会有所帮助
标签: r dictionary maps data-visualization geosphere