用R或Python中的邮政编码绘制彩色地图

gap*_*ppy 30 python graphics zipcode r

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

是否有任何包和代码可以让我这样做?

Edu*_*oni 38

我假设你想要静态地图.

alt text http://files.eduardoleoni.com/mapUS.png

1)在census.gov 获取zip边界和状态边界的shapefile:

2)使用我在这个SO问题中发布的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()
Run Code Online (Sandbox Code Playgroud)

  • 在www.census.gov上形成文件的链接已被破坏......我花了一段时间才找到它们.请尝试以下网址:http://www.census.gov/cgi-bin/geo/shapefiles2010/main.然后使用下拉列表选择"邮政编码列表区域"和"状态(和等效项)". (10认同)

Sha*_*ane 10

在R中有很多方法可以做到这一点(参见空间视图); 其中许多依赖于"地图"包.