在R,我想帮助尝试复制教程here为我自己的自定义SHP (形状文件)文件或地图,成为一个交互式的地图。
这张地图标出了北爱的小区域。它可以在here上找到。
下面是我到目前为止所采取的步骤。
我想问题出在geographyConfig数据的设置上...
任何帮助都将不胜感激……
# 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)加载rMaps.html不会生成相关的贴图,因为它只显示底部的切割,而不显示贴图。
发布于 2016-02-11 12:44:12
recordnotfound.com上的许多人要求作者回复这个帖子(在recordnotfound.com上)。我与rMaps项目的所有者Ramnath取得了联系。他建议有一个新项目可以提供增强的特性集:http://github.com/rstudio/leaflet
以下是有关leaflet项目的更多详细信息:https://recordnotfound.com/leaflet-rstudio-35205
发布于 2016-06-24 08:50:17
你看到http://www.r-bloggers.com/rmaps-mexico-map/了吗?我也遇到了类似的问题,我发现对于小范围的区域,你需要在下面的代码中操作比例参数。它确实有效。
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)https://stackoverflow.com/questions/29582992
复制相似问题