1

I am trying to replicate the example provided in the micromap R package of a linked map with the poverty rate for the 50 US states. I am trying to achieve the same results with a Shapefile from Germany. Here is my code:

library(micromap)
library(ggplot2)

setwd ('C:/Users/Jesus/Dropbox/linked maps/Chapter4')
ger<-readShapePoly("germany3.shp")
edPov<-read.csv('gerpoverty.csv')

statePolys <- create_map_table(ger, 'VARNAME_1')
head(statePolys)
lmplot(stat.data=edPov, 
       map.data=statePolys, 
       panel.types=c('labels', 'dot','map'),
       panel.data=list('Id1','poverty',NA),
       ord.by='poverty',
       grouping=5, median.row=F,
       map.link=c('Id1','VARNAME_1'))

When I tried to parse it into a flat table for use with ggplot2 the procedure does not work (instead of having 16 observations it has 8000 plus observations). Also when I try to plot the linked map, the following error appears on screen:

Error in `[.data.frame`(DF, , ord.by) : undefined columns selected

Here is the link to the files in a zip file:

https://www.dropbox.com/s/c43k755aadvu2z6/germany.rar

Any ideas or suggestions?

Thanks,

asado23
  • 366
  • 1
  • 7
  • 20
  • Which column in `gerpoverty.csv` contains the poverty data? When I load this file, it appears to contain the same information as the attributes table (`germany2.dbf`) in the shapefile ?? – jlhoward Feb 09 '14 at 23:12
  • Apparently there was a problem with the file, it should be corrected now. – asado23 Feb 13 '14 at 03:13
  • So I re-downloaded `germany.rar` from your link above and unzipped it. As before, the file `gerpoverty.csv` has the following fields: `ID_0, ISO, NAME_0, ID_1, NAME_1, Id1, NL_NAME_1, HASC_1, CC_1, TYPE_1, ENGTYPE_1, VALIDFR_1, VALIDTO_1, REMARKS_1, Shape_Leng, Shape_Area, x, y`. Which one is the poverty rate? – jlhoward Feb 13 '14 at 04:57
  • This is the updated link, the column is called poverty. https://www.dropbox.com/s/c43k755aadvu2z6/germany.rar – asado23 Feb 13 '14 at 05:06

1 Answers1

1

The problem is that create_map_table(...) takes whatever you give it as the id column (VARNAME_1 in your case), and puts that in a column called ID in the output (statePolys in your case). So now there is a statePolys$ID column with whatever you had in VARNAME_1. When you tell lmplot(...) to join on edPov$Id1 and statePolys$VARNAME_1, it can't find the latter column. Another way to say this is that the second element of map.link must always be ID. So this code works (I used the ID_1 column in both edPov and ger here, since that seems to contain a German State ID).

library(micromap)
library(ggplot2)

ger<-readShapePoly("germany3.shp")
edPov<-read.csv('gerpoverty.csv')

statePolys <- create_map_table(ger, 'ID_1')  # ID_1 stored in statePolys$ID
head(statePolys)
lmplot(stat.data=edPov, 
       map.data=statePolys, 
       panel.types=c('labels', 'dot','map'),
       panel.data=list('Id1','poverty',NA),
       ord.by='poverty',
       grouping=5, median.row=F,
       map.link=c('ID_1','ID'))

Here, ID_1 refers to edPoly$ID_1, and ID refers to statePolys$ID.

jlhoward
  • 58,004
  • 7
  • 97
  • 140
  • Great thanks, this seems to work perfectly. I am trying to replicate this type of coding for another example with Mexico's data. I basically have the code running but it consumes a lot of resources so I was wondering if there is an easier way to do it. Here is the link in case you are interested: http://gis.stackexchange.com/questions/86357/making-linked-micromaps-more-efficient – asado23 Feb 13 '14 at 16:24