[R-sig-Geo] Coloring continents

Hans-Jörg Bibiko bibiko at eva.mpg.de
Tue Aug 23 14:49:17 CEST 2011


On 23 Aug 2011, at 14:18, Etienne wrote:

> I believe there is an easy answer to my question, but I looked it up a bit
> and could not find anything. 
> I'm trying to have a simple world map (or better projection, if any) colored
> by continent. 
> One way to do that would be to enter a value for each country, but there is
> certainly an alternative to this time-costly & alienating solution, right?

Hi,

a very quick solution would be to use the data set "wrld_simpl" of package "maptools". Look at 

wrld_simpl at data

Here you find the column "REGION".


Then you can do the following:

library(maptools)
data(wrld_simpl)
my_cols <- c()
my_cols[20]  <- "red"
my_cols[3]  <- "green"
my_cols[143]  <- "blue"
my_cols[151]  <- "yellow"
my_cols[10]  <- "brown"
my_cols[1]  <- "white"
plot(wrld_simpl, col=my_cols[wrld_simpl at data$REGION+1])


Note: +1 is here necessary to catch the region "0"

The only problem is Russia since it belongs to Europe and Asia.

Cheers,

--Hans



**********************************************************
Hans-Joerg Bibiko
Max Planck Institute for Evolutionary Anthropology
Department of Linguistics
Deutscher Platz 6     phone:   +49 (0) 341 3550 341
D-04103 Leipzig       fax:     +49 (0) 341 3550 333
Germany               e-mail:  bibiko[AT]eva.mpg.de



More information about the R-sig-Geo mailing list