I have made a leaflet map to overlay some countries on a R leaflet webmap, however there seems to be something wrong with the projection/layout and part of Russia finds it way onto the adjacent frame.
The code:
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)
The main consequence of this problem is that if you are making a web-map it would look like this:
How do we fix this problem. Is any any low resolution world map, wherein we can select the countries based on ISO code and is geometrically more consistent.
Here's an example of what I meant by the comment.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With