RMaps ichoropleth with custom map / shp

In R, I would like to help in trying to reproduce the tutorial here for my own SHP (Shapefile) file or map to be an interactive choropleth diagram ..

Map of small areas of Northern Ireland. Which can be found here .

Below are the steps I have taken so far ...

I think the problem is setting geographyConfig data ...

Any help would be greatly appreciated ....

 # Download and unzip the data system('wget http://www.nisra.gov.uk/archive/geography/digital_products/SA2011_Esri_Shapefile.zip') system('unzip SA2011_Esri_Shapefile.zip') # Load libraries library(rgdal) library(rgeos) library(rMaps) shp.file <- 'SA2011.shp' # Convert projection system(paste0('ogr2ogr tmp.shp ', shp.file, ' -t_srs "+proj=longlat +ellps=WGS84 +no_defs +towgs84=0,0,0"')) # Read in the data xx <- readOGR(dsn=getwd(),layer='tmp') mm <- xx@data head(mm) n <- nrow(mm) dat.val <- mm$Hectares # Add extra year data mm <- mm[rep(seq(n),3),] mm$Hectares <- c(dat.val,rev(dat.val),dat.val/2) mm$year <- rep(c(2000:2002),each=n) colnames(mm)[1] <- 'ID' id.var <- 'SA2011' # Convert to json system(paste0('topojson -o tmp.json -s 1e-7 -q 1e5 tmp.shp -p ID=', id.var, ' --id-property ', id.var)) d1 <- ichoropleth(Hectares ~ ID, data = mm, ncuts = 9, pal = 'YlOrRd', animate = 'year', map = 'states' ) d1$set( geographyConfig = list( dataUrl = "tmp.json" ), scope = 'states', setProjection = '#! function( element, options ) { var projection, path; projection = d3.geo.mercator() .center([-7, 55]).scale(element.offsetWidth) .translate([element.offsetWidth / 2, element.offsetHeight / 2]); path = d3.geo.path().projection( projection ); return {path: path, projection: projection}; } !#' ) d1$save('rMaps.html', cdn = TRUE) 

Loading rMaps.html does not create the corresponding map, since it shows only the cuts at the bottom, but not the map.

+44
r rcharts
Apr 11 '15 at 21:01
source share
2 answers

Various people on recordnotfound.com asked the author to answer this topic (on recordnotfound.com). I contacted the owner of the rMaps project, Ramnath. He suggested that there is a new project that provides an expanded set of functions: http://github.com/rstudio/leaflet

More information about the advertising firmware project: https://recordnotfound.com/leaflet-rstudio-35205

+1
Feb 11 '16 at 4:44
source share

Have you seen http://www.r-bloggers.com/rmaps-mexico-map/ ? I had a similar problem, and I found that for small areas you need to manipulate the scale argument into the code bit below. He works.

  d1$set( geographyConfig = list( dataUrl = "tmp.json" ), scope = 'tmp', setProjection = '#! function( element, options ) { var projection, path; projection = d3.geo.mercator() .center([-5.832087, 54.605035]).scale(element.offsetWidth) .translate([element.offsetWidth / 2, element.offsetHeight / 2]); path = d3.geo.path().projection( projection ); return {path: path, projection: projection}; } !#' ) d1$save('rMaps.html', cdn = TRUE) 
0
Jun 24. '16 at 0:50
source share



All Articles