sgsg sgsg - 6 months ago 39
R Question

How to create a map with zipcode dataset? ( US Zipcode )

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,



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:

map(database="usa")# national boundaries

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 )

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.