我有一些美国人口统计和公司数据。 我想在一个州或一个较小的地区(例如城市)绘制邮政编码区域。每个区域将由特定于该区域的颜色和/或文本注释。输出类似于http://maps.huge.info/,但a)带有注释文本; b)pdf输出; c)R或Python中的脚本。
是否有任何包和代码可以让我这样做?
我假设你想要静态地图。
(来源: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()
在R中有很多方法可以做到这一点(参见spatial view);许多这些depend on the "maps" package。
require(gmaps)
data(USArrests)
attach(USArrests)
grid.newpage()
grid.frame(name="map")
grid.pack("map",USALevelPlot(states=rownames(USArrests),levels=Murder,col.fun=reds),height=unit(1,'null'))
grid.pack("map",gradientLegendGrob(at=quantile(Murder),col.fun=reds),side="bottom",height=unit(.2,'npc'))
detach(USArrests)
有人可能会有更直接的东西给你,但我发现O'Reilly的'R中的数据混搭'非常有趣......部分地,它是家庭止赎拍卖的空间映射。
在Python中,您可以使用美国人口普查中的shapefile和basemap
包。以下是根据人口统计的filling in states的示例。
R中有一个丰富而复杂的软件包系列,用于绘制,分析和与GIS相关的其他功能。一个开始的地方是Spatial Data上的CRAN任务视图:这是一个复杂的,有时是神秘的世界,需要一些工作才能理解。
如果您正在寻找一个免费的,功能强大的地图应用程序,我可以建议:
MapWindow(mapwindow.com)
Daniel Levine at TechCrunch Trends用R中的maps
包做了很好的事情。他的网站上也有代码。
如果你想学习(类似Java的)新语言,那么保罗关于加工的建议 - 本弗里曾用来制作zipdecode - 也是一个很好的建议。
根据您的应用程序,很长一段时间可能会使用这样的东西:
http://googlemapsmania.blogspot.com/2006/07/new-google-maps-us-zip-code-mashups.html
映射数据。如果那不是您想要的,您可以从census.gov获取原始邮政编码shapefile并手动完成,这非常痛苦。
此外,如果你还没有看到它,这是一种与类似数据交互的简洁方法,并可能提供一些指示:
查看IBM http://manyeyes.alphaworks.ibm.com/manyeyes/提供的这款出色的在线可视化工具
EDIT FYI,ManyEyes使用Prefuse visualization toolkit作为其中的一些。尽管它是基于java的框架,但它们还为Web提供了Flash / ActionScript工具。