user187809
user187809

Reputation:

How to specify countries/region while 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 "include alaska", "exclude antartica" etc?

Upvotes: 7

Views: 10779

Answers (2)

Geek On Acid
Geek On Acid

Reputation: 6410

If you looking just for those areas, the brutal solution would be to use world map, specify USA as a region and define latitude/longitude to create limits, so the map will only display specific area:

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

enter image description here

Upvotes: 4

IRTFM
IRTFM

Reputation: 263481

Quick answer:

nams <- map("world", namesonly=TRUE, plot=FALSE)

map("world", region=nams[-grep("Antarctica", nams)])

Longer answer:

The maps data in "world" is referenced by region names and these are generally character data in "continent:country" or "continent:subregion" format. To get those names which are in an external database, you need to first use maps("world" , ...) with parameters that return only the names and not all of hte other coordinates. If you want to find all the "Antarctica" containing entries you need to use grep() to identify their position in the returned names vector.

Upvotes: 5

Related Questions