[R] drawing filled countries according to data using map('world')? - follow up

Jens Hainmueller jens_hainmueller at ksg05.harvard.edu
Mon Mar 8 05:18:16 CET 2004


Hello,

this is a follow up on my previous inquiry regarding the use of the map
library (Becker and Wilks 1993).

Using the 'world' database I would like to draw filled countries in a world
map so that the filling colors of each country corresponds to the value of a
policy variable "fix.float" at a specific "year" (the goal is to visualize a
policy diffusion pattern over time using different maps for year=1985, 1990,
etc.).

In my dataset [Test] I have created a vector 'map.name' that contains
country names that I have made identical to the country names in file
world.N in .../library/maps/mapdata/.

> Test[1:10,]
   region fix.float wbcode  name year dv dv.lag map.name polygon
1     lac        NA    ABW Aruba 1973 NA     NA    Aruba    1936
2     lac        NA    ABW Aruba 1974 NA     NA    Aruba    1936
3     lac        NA    ABW Aruba 1975 NA     NA    Aruba    1936
4     lac        NA    ABW Aruba 1976 NA     NA    Aruba    1936
5     lac        NA    ABW Aruba 1977 NA     NA    Aruba    1936
6     lac        NA    ABW Aruba 1978 NA     NA    Aruba    1936
7     lac        NA    ABW Aruba 1979 NA     NA    Aruba    1936
8     lac        NA    ABW Aruba 1980 NA     NA    Aruba    1936
9     lac        NA    ABW Aruba 1981 NA     NA    Aruba    1936
10    lac        NA    ABW Aruba 1982 NA     NA    Aruba    1936

Now I would like to translate the country names in the 'world' database to
the country names in my dataset (following Becker and Wilks 1993). For some
reason, the translation does not work.

> map.country<-  map(database = "world", names=T,plot=F)
> state.to.map <- match(map.name,map.country)
> color <- dv[state.to.map, year == 1980]
Error in dv[state.to.map, year == 1980] : incorrect number of dimensions

> color <- dv[state.to.map, year == 1980]/100
Error in dv[state.to.map, year == 1980] : incorrect number of dimensions

What am I doing wrong? (there are a few values missing in "fix.float")

Thanks for your help!

Best
Jens Hainmueller




More information about the R-help mailing list