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

天大地大妈咪最大 提交于 2019-12-04 05:48:01

问题


for a school project I have to map some data on a geographical map in R. Therefore I've got some data containing the zipcode and many other information (just no more information on the state, county or whatever). I've been trying to point out on a map of the usa first all the zips I have. Just dots. Afterwards I wanted to mix and match the criteria like the count of zips I have in the data (e.g. the zips that appear very often I wanted to colour dark and the less often ones in a lither colour, later I wanted to point out e.g. the number of churns in a state). Can somebody help me out on how I can do this?

thanks a lot


回答1:


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:



来源:https://stackoverflow.com/questions/12858533/how-do-i-map-on-a-geographical-map-data-in-r-just-given-the-us-zipcodes

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