how do I map (on a geographical map) data in R just given the US Zipcodes

回眸只為那壹抹淺笑 提交于 2019-12-02 10:17:29

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.

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 )

Now plot the map of the US:

map( "usa" )

Load the zipcode data

data( "zipcode" )

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 )

Here is the result:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!