Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlighting specific countries (Ethiopia, Uganda, Kenya) using rworldmap library and map function

Tags:

r

maps

rworldmap

I am using this code using the package mapdata, however it only show the three countries I have selected, and I cannot see the rest of the world´s map boundaries.

map("world", 
    regions=c("ethiopia", "kenya", "uganda"), 
    exact = TRUE, 
    fill=TRUE, 
    col=c(1,2,3))

How can I show the rest of the world's map boundaries while highlighting my three selected countries?

like image 524
Carvalho Avatar asked Apr 02 '13 20:04

Carvalho


1 Answers

Here is an example without rworldmap:

require(mapdata)

# get the names
cc <- map('world', names = TRUE, plot = FALSE)
take <- unlist(sapply(c("ethiopia", "kenya", "uganda"), grep, tolower(cc), value = TRUE))

# world
map()
# add the selected countries in grey to the plot
map('world', regions=take, fill=TRUE, col='grey50', add = TRUE)

enter image description here

like image 109
EDi Avatar answered Sep 22 '22 08:09

EDi