2015-04-11 11 views
45

In R, vorrei aiuto nel tentativo di replicare il tutorial here per il mio proprio file personalizzato SHP (Shapefile) o sulla mappa per essere una mappa interattiva choropleth ...rMaps ichoropleth con la mappa custom/shp

La mappa è delle piccole aree dell'Irlanda del Nord. Quale può essere trovato here.

Qui di seguito sono i passi che ho preso finora ...

Credo che il problema è l'impostazione dei dati geographyConfig ...

Qualsiasi aiuto sarebbe molto apprezzato ....

# 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 <- [email protected] 
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) 

Caricamento rMaps.html non produce la mappa pertinente, in quanto mostra solo i tagli in basso ma non la mappa.

+0

Caricamento 'rMaps.html' non produce la mappa rilevante, ma solo la parte inferiore perché innesca errori JavaScript come si può vedere nella console JavaScript in Chrome, o l'ispettore Web in Safari. Non ho idea di cosa causa questi errori JavaScript. – WhiteViking

risposta

1

Diverse persone su recordnotfound.com hanno chiesto all'autore di rispondere a questa discussione (su recordnotfound.com). Mi sono messo in contatto con il proprietario del progetto rMaps, Ramnath. Egli ha suggerito che ci sia un nuovo progetto che offre un set di funzionalità migliorata: http://github.com/rstudio/leaflet

Qui ci sono ulteriori dettagli sul progetto volantino: https://recordnotfound.com/leaflet-rstudio-35205

+0

Aggiungi ulteriori dettagli alla tua risposta – NSNoob

+0

Il volantino è fantastico. Questo è un buon punto per iniziare a cercare nel volantino http://stackoverflow.com/questions/29260685/use-of-popupoptions-in-leaflet-package – GlennFriesen

0

Hai visto http://www.r-bloggers.com/rmaps-mexico-map/? Stavo riscontrando un problema simile e ho scoperto che per le aree di piccole dimensioni è necessario modificare l'argomento della scala nel bit di codice riportato di seguito. Funziona.

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)