[R] Mapping of countries
Rasmus Liland
jen@r|| @end|ng |rom @tudent@|ko@@u|o@no
Tue Mar 31 07:37:40 CEST 2020
On 2020-03-31 03:38 +0200, george brida wrote:
> i would like to plot the maps of the Gulf Cooperation Council (GCC)
> countries (KSA, Qatar, Bahrain, Kuwait, UAE and Oman) with these
> constraints: i/ KSA , Qatar and Bahrain have the same face color , ii/
> Kuweit and UAE with the same face color and iii/Oman with another face
> color.
Hi! Perhaps by using rnaturalearth, sf, and ggplot2:
world <- rnaturalearth::ne_countries(
scale = "medium",
returnclass = "sf")
grp1 <- c("Saudi Arabia", "Qatar", "Bahrain")
grp2 <- c("Kuwait", "United Arab Emirates")
grp3 <- c("Oman")
world$GCC <- rep(NA, length(world$name))
idx <- world$name %in% c(grp1, grp2, grp3)
world$GCC[idx] <- world$name[idx]
world$GCC
world$CountryGroup <- rep(NA, length(world$name))
world$CountryGroup[world$name %in% grp1] <- "i/ KSA, Qatar and Bahrain"
world$CountryGroup[world$name %in% grp2] <- "ii/ Kuwait and UAE"
world$CountryGroup[world$name %in% grp3] <- "iii/ Oman"
names(world)
world <- cbind(world, sf::st_coordinates(sf::st_centroid(world$geometry)))
ggplot2::ggplot(data = world) +
ggplot2::theme_bw() +
ggplot2::geom_sf() +
ggplot2::geom_sf(fill = NA, color = gray(.5)) +
ggplot2::geom_sf(ggplot2::aes(fill=CountryGroup)) +
# ggrepel::geom_text_repel(ggplot2::aes(x=X, y=Y, label=GCC)) +
# ggplot2::geom_sf(ggplot2::aes(fill=CountryGroup, label=CountryGroup)) +
ggplot2::coord_sf(xlim = c(32, 61),
ylim = c(10, 33),
expand = FALSE) +
ggplot2::xlab("Longitude") +
ggplot2::ylab("Latitude") +
ggplot2::ggtitle("Gulf Cooperation Council (GCC)")
Regards,
Rasmus
More information about the R-help
mailing list