一个国家的R地图包颜色填充给出了奇怪的结果

时间:2013-03-21 10:44:15

标签: r maps

以下代码会给出非常意外的结果。

我正试图在亚洲地图上为不同颜色的几个国家着色,颜色都混乱不堪。我做错了什么?

library(maps)
data(world.cities)
ctrys1=c("China","India","Australia","Taiwan","Malaysia","Thailand","Japan","Singapore","South Korea","Indonesia","Hong Kong")
cols=c('red','orange','white','white','white','white','white','red','white','white','white')
a=map('world',regions=ctrys1,ylim=c(-50,55),xlim=c(70,180),mar=c(0,0,0,0),fill=1,col=cols)

我在这里搜索了答案fill countries in a world map,或者来自r chopleopleth挑战的这个链接似乎没有答案。我怀疑是因为这些地区并不明显,但我不清楚如何提取它们。

http://www.thisisthegreenroom.com/2009/choropleths-in-r/

1 个答案:

答案 0 :(得分:2)

您可以使用value = tag这样的格式,并在exact = TRUE的调用中包含map ...

library(maps)
data(world.cities)
ctrys1=c("China","India","Australia")
cols=c("China"='red',"India"='orange',"Australia"='green')
a=map('world',regions=ctrys1, exact = TRUE , ylim=c(-50,55),xlim=c(70,180),mar=c(0,0,0,0),fill=1,col=cols)

enter image description here