R maps()中的县FIPS准确吗? [英] Are county FIPS accurate in R maps()?

查看:69
本文介绍了R maps()中的县FIPS准确吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行以下代码时...

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?

我正在使用maps_2.3-11

I'm using maps_2.3-11

推荐答案

简短的答案是您做错了.您正在访问的名称与县数据库中的多边形顺序不同.要执行您想要的操作,您应该使用以下命令:

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)

或者,如果您确实确实需要按 state,county 名称映射辅助值,则可以执行以下操作:

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)

这篇关于R maps()中的县FIPS准确吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆