R 地图颜色错误,但图例上指定的颜色正确?
我一直在绘制一张choropleth地图,当我将绘制的颜色与分配给它的数字进行比较时,它并不适合 这是我的数据R 地图颜色错误,但图例上指定的颜色正确?,r,map,colors,legend,R,Map,Colors,Legend,我一直在绘制一张choropleth地图,当我将绘制的颜色与分配给它的数字进行比较时,它并不适合 这是我的数据 zip latitude longitude count2.x count2.freq reg colorBuckets colma 99501 61.21680 -149.87828 AK 67 Alaska 1 #EDF8FB 35010 32.90343 -85.9266
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)
库(“zipcode”)
图书馆(“地图”)
图书馆(“plyr”)
图书馆(“RColorBrewer”)
颜色=brewer.pal(6,“BuGn”)
数据(zipcode)
merge1阿拉斯加地区在map
功能中不可用。因此,您的地图显示了nodull$reg
(即阿拉巴马州和加利福尼亚州)的第二个和第三个条目。但是你的第一和第二种颜色被使用了
要以所需颜色打印这些状态,请使用命令
map("state", regions=nodupl$reg[2:3], exact=FALSE,
col = colors[nodupl$colorBuckets][2:3], fill = TRUE,resolution = 0,lty = 0)
但我也建议搜索阿拉斯加地图。谢谢,但如果搜索包含阿拉斯加的地图,我将从0重新开始,并且必须重新计算所有代码。我不能删除此地图的行,而下一个地图的行,我需要重新开始。另外,关于我和传奇的问题,你有什么建议吗。我怎么能把它从画面中移开一点呢?另外还有一个问题,我有更多的数据,所以我需要更多的行,我尝试了这个映射(“state”,regions=nodupl$reg[2:6,8:10,12:44],exact=FALSE,col=colors[nodupl$colorbackes][2:6,8:10,12:44],fill=TRUE,resolution=0,lty=0),但它不起作用