Reputation: 615
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?
Upvotes: 2
Views: 2256
Reputation: 18749
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)
For more elegant ways of plotting zip code related data, you should have a look at the answers for this SO question.
Upvotes: 1