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

StackOverflow https://stackoverflow.com/questions/15774073

  •  31-03-2022
  •  | 
  •  

Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top