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

1

7

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?

Sine answered 2/4, 2013 at 20:50 Comment(0)
R
10

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

Roshelle answered 2/4, 2013 at 21:11 Comment(2)
+1, but I'd use a bor = "red"or similar, to highlight the selected countries a little more.Boley
Thank you very much Simon. Just what I wanted! Perfect!Sine

© 2022 - 2024 — McMap. All rights reserved.