R中的地理映射

时间:2014-12-23 10:11:01

标签: r dictionary leaflet

我在国家/地区拥有交易数据。

数据样本:

TransID CountryOrigin(CO)  CountryDestination(CD)  COLat         COLong       CDLat        CDLong

1          India               Australia        20.593684     78.962880   -25.274398   133.775136

现在我想将国家/地区的来源和目的地与交易数量相关联。如果交易量很高,那么该行的宽度将大于低交易区域。

我希望可视化更像下面的图像 (使用worldmap中的国家/地区名称标签) enter image description here

1 个答案:

答案 0 :(得分:2)

我不太确定,但就我所知,你正在寻找这样的东西: http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/

如果您希望在较高的交易区域中线条的宽度更大,则必须在这些线条中将lwd parameter设置得更高:

#Load packages
install.packages("maps")
install.packages("geosphere")
library(maps)
library(geosphere)

#Create a Map
xlim <- c(55.593, 140.9628)
ylim <- c(-30.2743, 40.775)
map("world", col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05, xlim=xlim, ylim=ylim)

#create a line
lat_india <- 20.5936
lon_india <- 78.96288
lat_aussie <- -25.2743
lon_aussie <- 133.77
inter <- gcIntermediate(c(lon_india, lat_india), c(lon_aussie, lat_aussie), n=50, addStartEnd=TRUE)

#plot the line (lwd represents the width of the line)
lines(inter, lwd=3)