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

Spencer Graves spencer.graves at pdf.com
Mon Mar 8 05:10:51 CET 2004


      I have no experience with maps, but I can see a problem with 
"dv[state.to.map, year == 1980]" that would generate the error you got, 
"incorrect number of dimensions":  This expression assumes "dv" is a 
2-dimensional array, and R thinks you want the rows specified by 
"state.to.map" and the columns specified by "year == 1980". 

      If "dv" is a vector, I'm guessing that the following might give 
you what you want: 

      dv[state.to.map][(year == 1980)[state.to.map]]

      I assume here that "state.to.map" is a numeric vector of the same 
length as "dv", and "year" is a numeric vector of the same length.  If 
"dv" is a 3-dimensional array, then the following might return what you 
want: 

      dv[state.to.map, drop=F][(year == 1980)[state.to.map],,]

      Please check help.start() -> "An Introduction to R" ->

    * Simple manipulations numbers and vectors
      <#Simple%20manipulations%20numbers%20and%20vectors>:
    * Objects <#Objects>:
    * Factors <#Factors>:
    * Arrays and matrices <#Arrays%20and%20matrices>:
    * Lists and data frames <#Lists%20and%20data%20frames>:

      Hope this helps.  spencer graves

Jens Hainmueller wrote:

>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
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>  
>




More information about the R-help mailing list