1

The following code gives very unexpected results.

I'm trying to colour a few countries with different colours in a map of Asia, and the colors are all jumbled up. What am I doing wrong?

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)

I've searched SO an the answers here fill countries in a world map or this link from the r choropleth challenge don't seem to have an answer for this. I suspect it is because the regions aren't obvious but I'm not clear how to extract them.

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

4

1 回答 1

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)

在此处输入图像描述

于 2013-03-21T10:59:13.813 回答