[R] creating a world map of eco-climatic zones

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Jul 19 01:02:46 CEST 2007


On 7/18/07, Tanja Srebotnjak <Tanja.Srebotnjak at yale.edu> wrote:
> Hello R users:
>
> I would like to produce a world map with countries colored according to whether
> they fall into one of 7 eco-climatic zones. For simplicity, each country is
> allocated to exactly 1 eco-climatic zone. For this purpose I have looked at the
> map and mapdata packages, which contain world maps composed of polygons (1 for
> each country, it seems). Each of the polygons can be referred to by a region
> name in the map package.
>
> I am thinking, I would do something like
>
> map(region=c('Germany', 'Switzerland',...), fill=TRUE, col='blue')
>
> for each of the 7 eco-climatic zones.
>
> My question is, what are the names used in the world map dataset for each
> country and how can I get them?

> library(maps)
> wmap <- map('world', plot = FALSE, fill = TRUE)
> str(wmap)
List of 4
 $ x    : num [1:27636] -133 -132 -132 -132 -130 ...
 $ y    : num [1:27636] 58.4 57.2 57.0 56.7 56.1 ...
 $ range: num [1:4] -180.0  190.3  -85.4   83.6
 $ names: chr [1:2284] "Canada" "South Africa" "Denmark" "Great
Lakes:Superior, Huron, Michigan" ...
 - attr(*, "class")= chr "map"

So wmap$names will give you the names you want.

> Perhaps there's also a smarter way to produce this map, in which case, your
> advise is greatly appreciated as well.

If you construct a suitable color vector (with the same order as
$names), you should be able to do the whole thing in one call.

> Lastly, some countries (mostly large ones such as USA, Russia, Canada, China)
> fall into multiple eco-climatic zones. Assume I could get geographical
> coordinates for polygons describing the sub-country portion falling into a
> single eco-climatic zone, is there a way to improve the above map to show
> portions of countries belonging to a specific eco-climatic zone?

wmap$x and wmap$y are exactly that (coordinates of polygons, with NA's
separating polygons). You should be able to add a few more, add
suitable names, and supply the result as the 'database' argument to
another call to map().

-Deepayan



More information about the R-help mailing list