JD *_*ong 59 r map geolocation geospatial
R中有很多包用于各种空间分析.这可以在CRAN任务视图中看到:空间数据分析.这些软件包数量众多且各种各样,但我想做的只是一些简单的专题图.我有县和州FIPS代码的数据,我有县和州边界的ESRI形状文件和随附的FIPS代码,允许加入数据.如果需要,形状文件可以很容易地转换为其他格式.
那么用R创建专题地图最直接的方法是什么?
这张地图看起来像是用ESRI Arc产品创建的,但这是我想用R做的事情:
alt text http://www.infousagov.com/images/choro.jpg 从这里复制的地图.
Edu*_*oni 60
以下代码对我很有帮助.稍微定制它就完成了. alt text http://files.eduardoleoni.com/map.png
library(maptools)
substitute your shapefiles here
state.map <- readShapeSpatial("BRASIL.shp")
counties.map <- readShapeSpatial("55mu2500gsd.shp")
## this is the variable we will be plotting
counties.map@data$noise <- rnorm(nrow(counties.map@data))
Run Code Online (Sandbox Code Playgroud)
热图功能
plot.heat <- function(counties.map,state.map,z,title=NULL,breaks=NULL,reverse=FALSE,cex.legend=1,bw=.2,col.vec=NULL,plot.legend=TRUE) {
##Break down the value variable
if (is.null(breaks)) {
breaks=
seq(
floor(min(counties.map@data[,z],na.rm=TRUE)*10)/10
,
ceiling(max(counties.map@data[,z],na.rm=TRUE)*10)/10
,.1)
}
counties.map@data$zCat <- cut(counties.map@data[,z],breaks,include.lowest=TRUE)
cutpoints <- levels(counties.map@data$zCat)
if (is.null(col.vec)) col.vec <- heat.colors(length(levels(counties.map@data$zCat)))
if (reverse) {
cutpointsColors <- rev(col.vec)
} else {
cutpointsColors <- col.vec
}
levels(counties.map@data$zCat) <- cutpointsColors
plot(counties.map,border=gray(.8), lwd=bw,axes = FALSE, las = 1,col=as.character(counties.map@data$zCat))
if (!is.null(state.map)) {
plot(state.map,add=TRUE,lwd=1)
}
##with(counties.map.c,text(x,y,name,cex=0.75))
if (plot.legend) legend("bottomleft", cutpoints, fill = cutpointsColors,bty="n",title=title,cex=cex.legend)
##title("Cartogram")
}
Run Code Online (Sandbox Code Playgroud)
绘制它
plot.heat(counties.map,state.map,z="noise",breaks=c(-Inf,-2,-1,0,1,2,Inf))
Run Code Online (Sandbox Code Playgroud)
Jay*_*Jay 17
以为我会在这里添加一些新信息,因为自发布以来,围绕此主题已经有了一些活动.以下是Revolutions博客上"Choropleth Map R Challenge"的两个很棒的链接:
希望这些对于查看此问题的人有用.
祝一切顺利,
松鸦
小智 11
看看包裹
library(sp)
library(rgdal)
Run Code Online (Sandbox Code Playgroud)
这对地理数据很好,而且
library(RColorBrewer)
Run Code Online (Sandbox Code Playgroud)
对着色很有用.这张地图是用上面的包和这段代码制作的:
VegMap <- readOGR(".", "VegMapFile")
Veg9<-brewer.pal(9,'Set2')
spplot(VegMap, "Veg", col.regions=Veg9,
+at=c(0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5),
+main='Vegetation map')
Run Code Online (Sandbox Code Playgroud)
"VegMapFile"是一个shapefile,"Veg"是显示的变量.一点点工作可能会做得更好.我似乎不允许上传图片,这里是图片的链接:
| 归档时间: |
|
| 查看次数: |
27065 次 |
| 最近记录: |