12.3 Make a Map

library(tidyverse)
library(sf)
library(rnaturalearth)

africa <- ne_countries(continent = "Africa", 
                       returnclass = "sf")


# Africa with colours
ggplot(data = africa) +
  geom_sf(aes(fill=name), 
          color= "white", 
          linewidth = 1,
          show.legend = F) +
  coord_sf() +
  ggthemes::theme_map() +
  labs(title = "Africa",
       subtitle = "Countries in Africa",
       caption = "Sample data from rnaturalearth") +
  # add north arrow
  ggspatial::annotation_north_arrow(which_north = "true",
                         style = ggspatial::north_arrow_fancy_orienteering()) +
  # add scale bar
  ggspatial::annotation_scale(location = "tr",
                              pad_y = unit(0.1, "cm")) 

## Coordinate Reference System (CRS)

st_crs(africa)
## Coordinate Reference System:
##   User input: WGS 84 
##   wkt:
## GEOGCRS["WGS 84",
##     DATUM["World Geodetic System 1984",
##         ELLIPSOID["WGS 84",6378137,298.257223563,
##             LENGTHUNIT["metre",1]]],
##     PRIMEM["Greenwich",0,
##         ANGLEUNIT["degree",0.0174532925199433]],
##     CS[ellipsoidal,2],
##         AXIS["latitude",north,
##             ORDER[1],
##             ANGLEUNIT["degree",0.0174532925199433]],
##         AXIS["longitude",east,
##             ORDER[2],
##             ANGLEUNIT["degree",0.0174532925199433]],
##     ID["EPSG",4326]]

12.3.1 Bounding Box

ctr_africa <- africa %>%
  filter(name == "Central African Rep.")
ctr_africa %>% st_bbox()
##     xmin     ymin     xmax     ymax 
## 14.45941  2.26764 27.37423 11.14240