Plotting country shapefiles next to each other preserving scale

Viewed 75

What I want to do

Using country-level data from the Natural Earth shapefile dataset, I would like to plot countries next to one another to demonstrate their size difference. For example, I'd love to plot Cameroon and Ethiopia next to the Democratic Republic of Congo to impress upon my students the variation in size of countries in Africa.

What I've tried

Using R, here is what I've tried:

Using sf::st_read I've imported the shapefiles as countries.

library(sf) # Easily work with spatial objects
library(tidyverse) # Brings in GGPlot
library(gridExtra) # Allows you to easily plot multiple GGPlots

gridExtra::grid.arrange(
ggplot(data = subset(countries, SOVEREIGNT %in% "Cameroon")) + geom_sf(),
ggplot(data = subset(countries, SOVEREIGNT %in% "Ethiopia")) + geom_sf(),
ggplot(data = subset(countries, SOVEREIGNT %in% "Democratic Republic of the Congo")) + geom_sf(),
ncol = 3)

Results

The result is three maps that are mismatched in scale. Despite being the largest of the countries, the DRC looks smaller than Cameroon, the smallest of the countries.

Are there any elegant ways to do this comparison?

1 Answers

There are a few options.

A) Extract the countries then use affine operators to place them next to each other

Cameroon = subset(countries, SOVEREIGNT %in% "Cameroon")
Ethiopia = subset(countries, SOVEREIGNT %in% "Ethiopia")
DRC = subset(countries, SOVEREIGNT %in% "Democratic Republic of the Congo")
buffer = 1
Cameroon = st_geometry(Cameroon) - st_centroid(Cameroon)$geometry
DRC = st_geometry(DRC) - st_centroid(DRC)$geometry 
DRC = DRC - c(st_bbox(st_geometry(DRC))['xmin'],0)
DRC = DRC + c(st_bbox(st_geometry(Cameroon))['xmax'] + buffer,0)
Ethiopia = st_geometry(Ethiopia) - st_centroid(Ethiopia)$geometry
Ethiopia = Ethiopia - c(st_bbox(Ethiopia)['xmin'],0)
Ethiopia = Ethiopia + c(st_bbox(st_geometry(DRC))['xmax'] + buffer, 0)

ggplot(c(Cameroon, Ethiopia, DRC)) + geom_sf() + theme_minimal()

enter image description here

B) Use facets

countries %>%
  subset(SOVEREIGNT %in% c("Cameroon", "Ethiopia", "Democratic Republic of the Congo")) %>%
  ggplot() + 
  geom_sf() +
  facet_grid(~SOVEREIGNT)

enter image description here

C) simply plot them in their correct locations without moving or separating them:

countries %>%
  subset(SOVEREIGNT %in% c("Cameroon", "Ethiopia", "Democratic Republic of the Congo")) %>%
  ggplot() + 
  geom_sf()

enter image description here

Related