How to specify the country / region when creating maps in R?

map ("usa") by default displays a map without Alaska and Hawaii. map ("world") has Antartica by default. Is there any way to say "enable alaska", "exclude antartica", etc.?

+7
source share
2 answers

Quick response:

nams <- map("world", namesonly=TRUE, plot=FALSE) map("world", region=nams[-grep("Antarctica", nams)]) 

Longer answer:

Map data in the "world" refers to the names of the regions, and they are usually symbolic data in the format "continent: country" or "continent: subregion". To get the names that are in the external database, you first need to use maps ("world", ...) with parameters that return only names, and not all other coordinates. If you want to find all the entries in Antarctica, you need to use grep () to identify their position in the returned name vector.

+5
source

If you look only at these areas, the cruel decision is to use a world map, specify the USA as region and define latitude / longitude to create restrictions, so only a certain area will be displayed on the map:

 library(maps) long <- c(-180,-50) lat <- c(10,80) map("world",regions=".*usa",xlim=long,ylim=lat) 

enter image description here

+4
source

All Articles