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/

Community
  • 1
  • 1
Tahnoon Pasha
  • 5,848
  • 14
  • 49
  • 75

1 Answers1

2

You can use a value = tag format like this and include exact = TRUE in the call to 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

Simon O'Hanlon
  • 58,647
  • 14
  • 142
  • 184