在R,我想帮助试图复制教程在这里为自己的自定义SHP(Shape文件)文件或映射是一个交互式的地区分布图...
该地图是北爱尔兰的小地区.哪个可以在这里找到.
以下是我到目前为止采取的步骤......
我认为问题是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)
Run Code Online (Sandbox Code Playgroud)
加载rMaps.html不会生成相关地图,因为它只显示底部的切口而不显示地图.
小智 1
recordnotfound.com 上的许多人要求作者回复此帖子(在 recordnotfound.com 上)。我联系了 rMaps 项目的所有者 Ramnath。他建议有一个新项目提供增强的功能集:http://github.com/rstudio/leaflet
以下是有关传单项目的更多详细信息:https://recordnotfound.com/leaflet-rstudio-35205
| 归档时间: |
|
| 查看次数: |
1117 次 |
| 最近记录: |