2

In my data, US zip codes are grouped into 4 groups: I need to highlight those zipcodes with different color for each group & to display the state names for those zip codes.

I was trying with zip.plot function of the muRL package.

Using this function I am able to highlight all the zipcodes I'm considering for my project, but not able to use different color scheme for those 4 groups & to display the state names.

How to find a solution?

j0k
22.8k28 gold badges81 silver badges90 bronze badges
asked Aug 6, 2012 at 10:39
2
  • I'm not familiar with this function but I will guess (judging by the content of the package muRL reference manual) that if your input data.frame (data) contains a column zip with your zip codes and a column group with the number of the group to which they belong you can probably do something like this: zip.plot(data, col=data$group) Commented Aug 6, 2012 at 11:07
  • 4
    That being said, please consider editting your question according to this guideline by adding a reproducible example and maybe showing the code you tried so far as it would be considerably easier to provide you with adequate answers that way. Commented Aug 6, 2012 at 11:08

1 Answer 1

1

This is probably not the most elegant solution but that should get you in the right direction, I hope.

First some random data:

library(muRL)
data(zips) #This is the file muRL's zip.plot function is calling: I'm gonna use it to extract random zip codes.
zip.data <- data.frame(zip = sample(zips$zip, 10), group = sample(1:4, 10, replace=TRUE))

Then your plot, with different colors per group:

zip.plot(zip.data, col = zip.data$group)

And for the state name, I'm using here the zips table again:

zips[zips$zip %in% zip.data$zip, ] -> zip_subset
text(zip_subset$lon, zip_subset$lat, labels = zip_subset$state, pos = 4, cex = 0.7, font = 2)

enter image description here

For more elegant ways of plotting zip code related data, you should have a look at the answers for this SO question.

answered Aug 13, 2012 at 8:14
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.