我有一些美国的人口统计和公司数据。
我想在一个州或一个较小的区域(例如城市)中绘制邮政编码区域。每个区域将由该区域特定的颜色和/或文本注释。输出将类似于http://maps.huge.info/,但a)带有注释文本; b)pdf输出; c)可在R或Python中编写脚本。

是否有允许我执行此操作的软件包和代码?

最佳答案

我假设您想要静态 map 。

python - 在R或Python中用邮政编码绘制颜色图-LMLPHP
(来源:eduardoleoni.com)

1)在census.gov上获取zip边界和state边界的shapefile:

2)使用我在此SO question中发布的plot.heat函数。

例如(假设您在 map 子目录中有maryland shapefile):

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()

08-17 21:49