library(maptools)
##substitute your shapefiles here
state.map <- readShapeSpatial("maps/st24_d00.shp")
zip.map <- readShapeSpatial("maps/zt24_d00.shp")
## this is the variable we will be plotting
zip.map@data$noise <- rnorm(nrow(zip.map@data))
## put the lab point x y locations of the zip codes in the data frame for easy retrieval
labelpos <- data.frame(do.call(rbind, lapply(zip.map@polygons, function(x) x@labpt)))
names(labelpos) <- c("x","y")
zip.map@data <- data.frame(zip.map@data, labelpos)
## plot it
png(file="map.png")
## plot colors
plot.heat(zip.map,state.map,z="noise",breaks=c(-Inf,-2,-1,0,1,2,Inf))
## plot text
with(zip.map@data[sample(1:nrow(zip.map@data), 10),] , text(x,y,NAME))
dev.off()
我想你需要静态地图。
(来源:eduardoleoni.com)
1)在census.gov上获取zip边界和state边界的形状文件:
2)使用我在SO question中发布的plot.heat函数。
例如(假设在map子目录中有maryland shapefile):
在R中有很多方法可以做到这一点(参见spatial view);其中很多方法都是depend on the "maps" package。
看看这个cool example of the US 2004 election。结果是这样的:
下面是一个稍微难看的模型示例that uses the "maps" package with "lattice".
这里有一个非常简单的例子using the "gmaps" package,它显示了每10万人中有10万人因谋杀被国家逮捕:
有人可能对你有更直接的建议,但我发现O'Reilly在R中的数据混搭非常有趣。。。在某种程度上,这是房屋止赎拍卖的空间映射。
http://oreilly.com/catalog/9780596804770/
相关问题 更多 >
编程相关推荐