0

I am trying use the micromap package in R, but something is not working. This is the code:

library(micromap)
library(rgdal)
library(ggplot2)

setwd ('C:/Users/Jesus/Dropbox/linked maps/Chapter4')
mexico<-readShapePoly("ESTADOS.shp")
gdp<-read.csv('mexico.csv')
gdp$CVE_ENT<-as.character(gdp$CVE_ENT)
statePolys <- create_map_table(mexico, 'CVE_ENT')

lmplot(stat.data=gdp,         
       map.data=statePolys,
       panel.types=c('labels','dot','map'),
       panel.data=list('estado','percapita', NA),
       ord.by='percapita',
       grouping=8, median.row=FALSE,
       map.link=c('CVE_ENT','ID'))

The code seems to work but produces the the following image with incomplete information:

enter image description here

As you can see in the image some states are not ploted. Any idea on why my code is not working?

The link to the files is here: https://www.dropbox.com/s/idvi1nlxq3uml3h/mexico.rar

Thanks,

  • I've checked the geometry, fixed topology problems & even simplified the spatial file by a factor of 20, but cannot get the code to work on this side either. I notice that even some of the example code for micromap isn't working for me - wondering if something is broken in the dependencies? – Simbamangu Feb 18 '14 at 14:44
  • I tried with a different shapefile file available here: dropbox.com/s/gncr2bkpifoq1a4/mexstates.zip And it got a little bit better. For the new file the id field is no longer CVE_ENT but ADMIN_NAME. – Jlkm Feb 18 '14 at 16:02
1

So the problem with the code was that the id field for the shape file and for the csv file were defined as character (Thanks to Mark Weber for this observation). The new code is:

library(micromap)
library(rgdal)
library(ggplot2)

setwd ('C:/Users/Jesus/Dropbox/linked maps/Chapter4')

mexico<-readShapePoly("mexstates.shp")

gdp<-read.csv('mexico.csv')
gdp$CVE_ENT<-as.numeric(gdp$CVE_ENT)
mexico$CVE_ENT<-as.numeric(mexico$CVE_ENT)
statePolys <- create_map_table(mexico, 'CVE_ENT')

lmplot(stat.data=gdp,         
       map.data=statePolys,
       panel.types=c('labels','dot','map'),
       panel.data=list('estado','growthgdp', NA),
       ord.by='growthgdp',rev.ord=T,
       grouping=8, median.row=FALSE,
       map.link=c('CVE_ENT','ID'))

and this is the result: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.