且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

给定美国邮政编码,我如何在R中映射(在地理地图上)数据

更新时间:2023-02-21 20:09:22

看看 R邮政编码包;该网站包含一些示例.该程序包具有所有邮政编码的地理坐标,因此在地图上显示它们会很简单.

Take a look at the R zipcode package; the website contains some examples. The package features geographical coordinates of all zipcodes, so it will be trivial to show them on a map.

这里是正确方向的另一个指针:安装软件包"maps"和"zipcode".将它们都加载到您的环境中:

Here is another pointer into the right direction: install the package "maps" and "zipcode". Load both of them into your environment:

library( zipcode ) ; library( maps )

现在绘制美国地图:

map( "usa" )

加载邮政编码数据

data( "zipcode" )

说,您有一些邮政编码,例如90001、46243、32920,并希望在地图上显示它们.

Say, you have some zipcodes, for example 90001, 46243, 32920 and you want to show them on the map.

selected <- zipcode[ zipcode$zip %in% c( "90001", "46243", "32920" ), ]

所选数据框包含有关邮政编码的信息.绘制它们.

The selected data frame contain information about the zipcodes. Plot them.

points( selected$longitude, selected$latitude, pch= 19, cex= 2 )
text( selected$longitude, selected$latitude, selected$zip, pos=3, cex= 2 )

这是结果: