Are FIPS counties accurate in R maps ()?

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 the highlighted value for the county that is not Maricopa ... This is the county of Mojave.

usa counties

Am I doing something wrong or suspecting data?

I am using maps_2.3-11

+4
source share
1 answer

Short answer: you are doing it wrong. The names you are viewing 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) 

enter image description here

Alternatively, if you really need to map auxiliary values ​​using 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) 

enter image description here

+2
source

All Articles