地图上的颜色错误但在传奇上分配了吗?

时间:2012-10-20 14:00:39

标签: r map colors legend

我一直在绘制一个等值区域地图,当我将绘制的颜色与它们重新分配给它的数字进行比较时,不适合。

所以这是我的数据

    zip latitude    longitude   count2.x  count2.freq   reg   colorBuckets  colma
99501   61.21680    -149.87828    AK          67      Alaska     1         #EDF8FB
35010  32.90343      -85.92669    AL        1582      Alabama    3         #99D8C9
90001   33.97291    -118.24878    CA       20970    California   6         #006D2C
20001   38.90771    -77.01732     DC         952         NA      2         #CCECE6

所以我从一开始就使用的代码是以下

    library("zipcode")
library("maps")
library("plyr")
library("RColorBrewer")
colors=brewer.pal(6, "BuGn")
data(zipcode)
merge1<-merge(zipcode, tel2, by.x='zip', by.y='zip_code', all.y=TRUE)
result<- ddply(merge1, .(state), transform, count2 = count(state))
#remove NA's#
final<- result[complete.cases(result),]
#remove duplicates#
nodupl <- final[!duplicated(final$state),]
#add state to abbreviations#
nodupl$reg<-state.name[match(nodupl$count2.x, state.abb)]
#intervalle bestimmen#
nodupl$colorBuckets<- as.numeric(cut(nodupl$count2.freq, c(0,500,1000,5000,10000,15000,22000)))
#intervall legend#
text<- c("< 500", "500 - 999", "1000 - 4999","5000 - 9999", "10000 - 14999", "15000 - 22000")
#see what color is assign to where#
nodupl$colma<- colors[nodupl$colorBuckets]
map("state",regions=nodupl$reg, exact=FALSE, col = colors[nodupl$colorBuckets],  fill = TRUE,resolution = 0,lty = 0)
map("state",col = "black",fill=FALSE,add=TRUE,lty=1,lwd=1)
#legend plotten#
par(xpd=TRUE)
legend("bottomleft", text, horiz=FALSE, fill=colors)

所以问题再次出现,如果我看到颜色被正确分配的图例,但如果我仔细检查我的列(行count2.freq)中的数字与地图上的颜色,他们不适合。例如,加利福尼亚真的是浅色的但它应该是黑暗的。有没有人看到做错了什么。加上我在传奇方面的位置有点麻烦,就像我在地图上一样,所以我不再看地图了。我能做些什么呢? 感谢你的帮助,即使它是星期六

1 个答案:

答案 0 :(得分:0)

map功能无法使用阿拉斯加地区。因此,您的地图显示nodupl$reg(即阿拉巴马州和加利福尼亚州)的第二和第三个条目。但是使用了第一种和第二种颜色。

要以所需颜色打印这些状态,请使用命令

map("state", regions=nodupl$reg[2:3], exact=FALSE,
    col = colors[nodupl$colorBuckets][2:3],  fill = TRUE,resolution = 0,lty = 0)

但我也建议您搜索阿拉斯加地图。