1

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

user1741021
  • 333
  • 2
  • 4
  • 9
  • doesn't it defeat the purpose of the homework if we tell you what to do? – thecoshman Oct 12 '12 at 11:58
  • 1
    @thecoshman why, the ability to solve a problem includes the ability to post relevant questions and the ability to use the answers. Enough if we point that person to the right direction. Also, the OP was sincere about the task. – January Oct 12 '12 at 12:02
  • well to make the maps is one thing in addition to that I have to make up some economic problems that can be solved with that map. thats why I really need some help in making those maps – user1741021 Oct 12 '12 at 12:10
  • @January well, the OP is not asking for anything in particular. SO is not intended for 'I want to do X' style of questions. If he perhaps asked how he could store the realation between zip-codes and location, then perhaps it would be a more valid question. – thecoshman Oct 12 '12 at 12:10
  • @thecoshman since I don't only want to map one thing I kept the question pretty open. By the way I'm a she but I think that doesn't matter. Anyways yes your question would bring it right to the point what I first need. show the location of the zipcodes on a map plus my prof told me to ask questions in a forum like this because she can't solve the problem herself – user1741021 Oct 12 '12 at 12:14
  • @user1741021 of course gender does not matter. Forgive me for presuming. Well, as you have clearly said, your question is far to vague, you are not looking for help with a particular problem or fault. As such, I do not consider it fit for this site. Perhaps if you could ask a more direct question? – thecoshman Oct 12 '12 at 12:22
  • Wait... your *professor* can't solve it so (s)he made _you_ go to the forums? This is perfect fodder for phdcomics.com ! – Carl Witthoft Oct 12 '12 at 17:08

1 Answers1

4

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:

enter image description here

January
  • 16,320
  • 6
  • 52
  • 74
  • I've been already on that page but I couldn't figure out how to use my zips that i have in my data. I see that this is a package but I want to map my data. Can I somehow show the duplicates from that package and my data in a map?would that work? – user1741021 Oct 12 '12 at 12:05
  • Yes, after you have installed the package, load the data and select these zipcodes that can be found in your data. You will need to know very basics of R, but I guess that is a part of your project. – January Oct 12 '12 at 12:18
  • I've already done that. installed the package and loaded the whole data. I'm an economics student and R isn't normaly a program we are working with. So I have no clue on how to proceed. I've tried to show me the zips I have and the program displayed all of them. But as a number on tha page if I try to put them on a map of the usa I just get failure – user1741021 Oct 12 '12 at 12:26
  • In addition to that I managed to make an excel sheet with all the longitude and latitude from the zips that I need, so I put this into R now. My problem is to show things on the maps. I have downloaded the maps and rworldmap packages but how do you show things on there? – user1741021 Oct 12 '12 at 12:29
  • I've been trying on this for 2 days now, please give me some further advice on how to solve my problem. – user1741021 Oct 12 '12 at 12:41
  • @January are you gone? please help me a little more :) – user1741021 Oct 12 '12 at 12:48
  • thanks a lot @january I know my questions seem pretty dumb but how do I manage to put the whole column in it. and does it make a difference if I use "" or ''?and could you please explain this l8ine to me selected <- zipcode[ zipcode$zip %in% c( "90001", "46243", "32920" ), ] I guess I name the zips selected that I map now and it refers to the package zipcode but after the [ where do I have to fill in my names from my data. I have about 6480 different zipcodes so I guess I leave out the text. – user1741021 Oct 12 '12 at 13:21
  • ok I did it. took me just 4 more hours but thanks for helping – user1741021 Oct 12 '12 at 17:44