Reputation: 559
When I run the following code...
require(maps)
colors <- data.frame(county=county.fips$polyname,color=rep("#FFFFFF",nrow(county.fips)), stringsAsFactors=FALSE)
colors[colors$county=="arizona,maricopa","color"] <- "#ABCABC"
map("county", col = colors$color, fill = TRUE)
I get a highlighted value for a county that is not Maricopa... It's Mohave county.
Am I doing something wrong, or is the data suspect?
I'm using maps_2.3-11
Upvotes: 4
Views: 1115
Reputation: 3485
The short answer is that you're doing it wrong. The names you're accessing are not in the same order as the polygons in the county database. To do what you want you should use the following:
map("county")
map("county", "arizona,maricopa", col="#ABCABC", fill=T, add=T)
As an alternative, if you really do need to map ancillary values by state,county
name you can do something like the following:
## Get state,county names in the order they will be plotted:
c <- map("county", namesonly=T)
c1 <- rep("#FFFFFF", length(c))
c1[which(c=="arizona,maricopa")] <- "#FF0000"
map("county", col=c1, fill=T)
Upvotes: 2