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
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