With R I want to make an animated choropleth map with the rMaps package and a custom map. I tried to follow the example of Diego Valle described here and to use the custom map info for Datamaps.

However, the map does not display. But, the legend with the proper fill key appears with the year animation bar. The topoJson file seems to be fine.

map = readOGR("https://raw.githubusercontent.com/gupierre/GHA_vol/master/Data/GHA_adm/GHA_adm1.topo.json", layer="admin_1",stringsAsFactors=F)

SDLOG<-read.table("https://raw.githubusercontent.com/gupierre/GHA_vol/master/Data/sdlog.csv", header=T,stringsAsFactors=F, sep =",")
 year          name      sdlog  type
>1 2004 Greater Accra 0.20030687 urban
>2 2005 Greater Accra 0.15322712 urban
>3 2006 Greater Accra 0.10782677 urban


d1 <- ichoropleth(sdlog ~ name, data = SDLOG[SDLOG$type=="rural",], ncuts = 7, pal = 'YlOrRd', animate = 'year',  map = 'admin_1')
  geographyConfig = list(
    dataUrl = "https://raw.githubusercontent.com/gupierre/GHA_vol/master/Data/GHA_adm/GHA_adm1.topo.json"
 scope = 'admin_1',
  setProjection = '#! function( element, options ) {
  var projection, path;
  projection = d3.geo.mercator()
  .center([8, -1]).scale(element.offsetWidth)
  .translate([element.offsetWidth / 2, element.offsetHeight / 2]);

  path = d3.geo.path().projection( projection );
  return {path: path, projection: projection};
  } !#'

Note: this question was asked on stackoverflow without success. I don't know the policy on GIS for posting questions from SO. Please advise in the comments if I am wrong in simply copy pasting my initial question.

  • Welcome to our site! The preferred method is to flag your original question for migration: that will create automatic links between the two versions but inform people that answers should be posted here if possible. – whuber Dec 7 '15 at 14:53
  • Did you ever find a solution to this? – RJJoling Apr 15 '18 at 8:30
  • I'm working on it but yours url are actually broken. Could you repair those or share your files with us ? – César Arquero Mar 18 '19 at 13:10

It is hard to tell what exactly are you trying to do because the url you are using as example actually doesn't show a thing. The same with your data url's. enter image description here

Anyway, here you have a simplyfied code (modifying a little bit the few registers that you are showing using head()) in order to get rid of this unanswered question.


#new path to csv
SDLOG <- read.table("csv.csv", header=T, stringsAsFactors=F, sep =",")
SDLOG <- mutate(SDLOG, state = c("UT", "NE", "AL")) #add place for plotting
  year          name     sdlog  type state
1 2004 Greater Accra 0.2003069 urban    UT
2 2005 Greater Accra 0.1532271 urban    NE
3 2006 Greater Accra 0.1078268 urban    AL
4 2004 Greater Accra 0.1555555 urban    UT
5 2007 Greater Accra 0.3000000 urban    NE
6 2005 Greater Accra 0.2500000 urban    AL

d1 <- ichoropleth(sdlog ~ state,
                  data = SDLOG[SDLOG$type=="urban",],
                  ncuts = 7,
                  pal = 'YlOrRd',
                  animate = 'year')


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.