【问题标题】:map with wrong colors but right assigned on legend?地图颜色错误但在图例上分配正确?
【发布时间】:2012-10-20 14:00:38
【问题描述】:

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

这是我的数据

    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)中的数字与地图上不适合的颜色,问题再次出现。例如,加利福尼亚的颜色很浅,但应该是深色的。有没有人看到做错了什么。另外,我在地图上定位图例时遇到了一些麻烦,所以我再也看不到地图了。我能做些什么呢? 感谢您的帮助,即使是星期六

【问题讨论】:

    标签: r map colors legend


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 谢谢,但如果我搜索包含阿拉斯加的地图,我将从 0 重新开始,我必须再次找出所有代码。我不能只删除这张地图的行吗?无论如何,下一个我需要重新开始。再加上你对我的传说问题有什么建议。我怎么能把它从图片中移开一点?加上其他问题我有更多的数据,所以我需要更多的行,我试过这个 map("state", region=nodupl$reg[2:6,8:10,12:44], exact=FALSE, col = colors[nodupl$colorBuckets][2:6, 8:10,12:44], fill = TRUE,resolution = 0,lty = 0) 但它不起作用
    猜你喜欢
    • 1970-01-01
    • 2018-08-21
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    • 2021-04-27
    • 2014-05-18
    • 2021-08-26
    • 1970-01-01
    相关资源
    最近更新 更多