我制作了一张传单地图,用于覆盖R传单webmap上的一些国家/地区,但是投影/布局似乎有些问题,而俄罗斯的一部分则发现它在相邻的框架上。
代码:
library(rworldmap)
library(countrycode)
## country is in text
cnt <- c("Russia","Afghanistan", "Albania"," Algeria"," Argentina"," Armenia", "Azerbaijan"," Bangladesh"," Belarus")
#convert to ISO3 code
iso3 = countrycode(cnt, "country.name", "iso3c")
df= as.data.frame(cnt)
malMap <- joinCountryData2Map(df, joinCode = "ISO3", nameJoinColumn = "cnt")
## subset data
dfapr <- malMap[malMap$ISO3 %in% iso3, ]
plot(dfapr)
我们如何解决这个问题。是否有任何低分辨率世界地图,其中我们可以根据ISO代码选择国家,并且在几何上更加一致。
答案 0 :(得分:5)
这是评论意思的一个例子。
library(sp)
library(maps)
library(maptools)
library(leaflet)
# make sure to use the latest maps package
# it was recently updated at the time of the answer
world <- map("world", fill=TRUE, plot=FALSE)
world_map <- map2SpatialPolygons(world, sub(":.*$", "", world$names))
world_map <- SpatialPolygonsDataFrame(world_map,
data.frame(country=names(world_map),
stringsAsFactors=FALSE),
FALSE)
cnt <- c("Russia", "Afghanistan", "Albania", "Algeria", "Argentina", "Armenia",
"Azerbaijan", "Bangladesh", "Belarus")
target <- subset(world_map, country %in% cnt)
leaflet(target) %>%
addTiles() %>%
addPolygons(weight=1)