-5

How to create a map in R with zipcode dataset?

data <- c("22313","10100","25001") [example zipcode]

In this moment, I have a dataset full of zipcode and I would like to print in a map and save it in pdf.

Best regards,

E.P.

sgsg
  • 23
  • 6
  • What have you tried? Where did you get the shapefiles from?.. You didn't get any shapefiles, did you? – cory Sep 19 '16 at 15:34
  • http://stackoverflow.com/search?q=%5Br%5D+zipcode+map – hrbrmstr Sep 19 '16 at 15:42
  • I get a dataset from Kaggle, and I would like to create a maps with the zipcode. I used the "maps" package but I don't know how to use it. – sgsg Sep 19 '16 at 15:50
  • Possible duplicate of [how do I map (on a geographical map) data in R just given the US Zipcodes](http://stackoverflow.com/questions/12858533/how-do-i-map-on-a-geographical-map-data-in-r-just-given-the-us-zipcodes) – Cyrus Mohammadian Sep 19 '16 at 17:10

1 Answers1

0

Try the following code which I modified from January at how do I map (on a geographical map) data in R just given the US Zipcodes:

pdf("myzipcodes.pdf")
library(maps)
map(database="usa")# national boundaries

library(zipcode)
data("zipcode")
myzips <- c("22313","83701","32301")
selected <- zipcode[ zipcode$zip %in% myzips, ]
points( selected$longitude, selected$latitude, pch= 19, cex= 2 )
text( selected$longitude, selected$latitude, selected$zip, pos=3, cex= 2 )
dev.off()

You provided two phony zip codes so I added a couple real ones.

In RStudio you can also export a plot as a PDF file using the 'export' menu.

Community
  • 1
  • 1
Brian O'Donnell
  • 1,836
  • 19
  • 29