[R-sig-Geo] Adding some data as colors to world map

Roger Bivand Roger.Bivand at nhh.no
Wed Mar 8 18:54:23 CET 2006


On Mon, 6 Mar 2006, Gregor Gorjanc wrote:

> Roger Bivand wrote:
> > On Mon, 6 Mar 2006, Gregor Gorjanc wrote:
> > 
> > 
> >>Hello!
> >>
> >>I am a total newbie to map handling, but a keen R user. I have some
> >>estimates by numbers per country (in names, such as Germany, France,
> >>...) and would like to add this information with use of color on world
> >>and perhaps additionally to Europe map. How can this be achieved in R?
> >>Any pointers to relevant literature/tutorials would be fine.
> >>
> >  
> > Welcome! The answer depends on how you want to represent the countries 
> > graphically. Do you want to display the formatted numbers on a map of 
> > country borders, to fill the country polygons with colour or shading 
> > representing the values of the numbers, or maybe to put a filled bubble at 
> > some point representing the countries?
> 
> Filling country polygons with different colors would be just fine.
> Perhaps also filled bubble, but that one might not be so good since our
> eyes are bad at interpreting circles. Are there any examples where I
> could start with? Say I would like to color Australia with blue, states
> with red, Argentina with green etc. I will rather play with some color
> palette, but that would be more than great for the start.
> 
> > Which countries? Are they already in the maps package (maybe not, some of 
> > the borders there are rather out-of-date)?
> > 
> > library(maps)
> > map("world", xlim=c(-12,35), ylim=c(35,65))
> > 
> > shows you a pretty old version of Europe! There are plenty of sources of 
> > border maps, but getting something matching the borders you need may 
> > require a bit of googling (usually looking for a vector representation).
> 
> Yes, my country is missing ;)
> 
> > Does anybody have recommended websites for current European national 
> > border data (preferably in a format we can read)?
> 
> Hmm, this is then the main bottleneck - the maps.

I've produced a world map with ISO3166 two-letter codes. To get your codes 
right - this lists out country names and codes:

as(world_countries, "data.frame")

then

countries <- c("AU", "US", "AR")
colours <- c("blue", "red", "green")
plot(world_countries, col=colours[match(world_countries$ISO3166, countries)])

gives the attached PNG. Shall I make an .RData file of the
SpatialPolygonsDataFrame object available?

Roger


> 
> > 
> >>Many thanks!
> >>
> >>
> > 
> > 
> 
> 
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no

-------------- next part --------------
A non-text attachment was scrubbed...
Name: coloured_countries.png
Type: image/png
Size: 5492 bytes
Desc: 
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20060308/df991255/attachment.png>


More information about the R-sig-Geo mailing list