R map包 - 如何在国家之间划线?

时间:2011-12-10 02:28:53

标签: r maps latitude-longitude

在R中,使用maps包和gcIntermediate函数,如何在两个国家/地区之间绘制线条?它需要lat-long,但我不确定我应该为国家提供什么样的长期(比如我想在美国和瑞典之间画一条线)

1 个答案:

答案 0 :(得分:8)

您可以使用多个地图,具体取决于信息/详细信息等。你需要,但为此,非常好的wrld_simpl会很好:

library(maptools)
library(geosphere)

data(wrld_simpl)

US_lat = wrld_simpl$LAT[wrld_simpl$NAME == 'United States']
US_lon = wrld_simpl$LON[wrld_simpl$NAME == 'United States']

SWE_lat = wrld_simpl$LAT[wrld_simpl$NAME == 'Sweden']
SWE_lon = wrld_simpl$LON[wrld_simpl$NAME == 'Sweden']

points = gcIntermediate(c(US_lon, US_lat), c(SWE_lon, SWE_lat), 100)

dev.new(width=6, height=4)
plot(wrld_simpl)
lines(points, col='red')

enter image description here