简体   繁体   中英

R maps package missing counties

I am attempting to make a heat map / choropleth / thematic plot of the USA by county using the R "maps" package. Unfortunately some counties seem to be missing from the database.

library(maps)
data(county.fips)
which(county.fips[,1] == 35006)
which(county.fips[,2] == 'new mexico,cibola')

results in no entries found

> library(maps)
> data(county.fips)
> which(county.fips[,1] == 35006)
integer(0)
> which(county.fips[,2] == 'new mexico,cibola')
integer(0)

I know that this fips code exists! (http://en.wikipedia.org/wiki/Cibola_County,_New_Mexico http://en.wikipedia.org/wiki/List_of_counties_in_New_Mexico )

Anyone know how I can make my full plot? All I could find on this was listed here: http://grokbase.com/t/r/r-sig-geo/0964515wmd/missing-county-in-maps

Thanks for your help!!

Ah ha, the problem is not with map, but county.fips. Cibola County does not appear in that dataset, so when I went to match my data {variable-to-plot, FIPS code} to the list, Cibola was always missing.

There is a work-around for displaying Cibola county... write an explicit line for the county that does not involve the county.fips dataset.

countynames <- match(county.fips[,"fips"], mydatavector$fips)
cibola_value <- mydatavector[which(mydatavector$fips == 35006)]
m <- map("county")
map("county", countynames, col=rainbow(100)[mydatavector$var_to_plot], fill=TRUE, add=TRUE)
map("county", "new mexico,cibola", col=rainbow(100)[cibola_value], fill=TRUE, add=TRUE)

Note: I also found that the map function had trouble plotting all counties in the US, but if I split up the call into 2 sets it worked.

Cibola county is not missing in "county" database. Should be enough to draw maps. See for example:

map.text('county', 'new mexico')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM