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

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

  •  31-03-2022
  •  | 
  •  

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?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top