Chapter 9 Making maps with R

Learning objectives:

  • Explore tools that help analysts produce maps with R packages
  • Discuss motivation for using the various technologies
  • Introduce some spatial calculations
library(colorspace)
library(dplyr)
library(ggplot2) # tidyverse data visualization package
library(grid)
library(leaflet) # for interactive maps
# library(mapdeck)
library(mapview)
library(sf)
library(spData)
library(spDataLarge)
library(terra)
library(tmap)    # for static and interactive maps

sessionInfo()
## R version 4.3.1 (2023-06-16)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.2 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0
## 
## locale:
##  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
##  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
##  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
## [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
## 
## time zone: UTC
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] grid      stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] tmap_3.3-3        mapview_2.11.0    leaflet_2.1.2     colorspace_2.1-0 
##  [5] lubridate_1.9.2   forcats_1.0.0     stringr_1.5.0     purrr_1.0.1      
##  [9] readr_2.1.4       tibble_3.2.1      tidyverse_2.0.0   ggplot2_3.4.2    
## [13] tidyr_1.3.0       dplyr_1.1.2       sp_2.0-0          spDataLarge_2.0.9
## [17] spData_2.2.2      terra_1.7-37      sf_1.0-13        
## 
## loaded via a namespace (and not attached):
##  [1] tidyselect_1.2.0        viridisLite_0.4.2       farver_2.1.1           
##  [4] fastmap_1.1.1           XML_3.99-0.14           digest_0.6.31          
##  [7] timechange_0.2.0        lifecycle_1.0.3         magrittr_2.0.3         
## [10] compiler_4.3.1          rlang_1.1.1             sass_0.4.6             
## [13] tools_4.3.1             utf8_1.2.3              yaml_2.3.7             
## [16] data.table_1.14.8       knitr_1.43              labeling_0.4.2         
## [19] htmlwidgets_1.6.2       bit_4.0.5               classInt_0.4-9         
## [22] RColorBrewer_1.1-3      abind_1.4-5             KernSmooth_2.23-21     
## [25] withr_2.5.0             leafsync_0.1.0          stats4_4.3.1           
## [28] tidyterra_0.4.0         fansi_1.0.4             e1071_1.7-13           
## [31] leafem_0.2.0            scales_1.2.1            dichromat_2.0-0.1      
## [34] cli_3.6.1               rmarkdown_2.22          crayon_1.5.2           
## [37] generics_0.1.3          rstudioapi_0.14         tzdb_0.4.0             
## [40] tmaptools_3.1-1         DBI_1.1.3               cachem_1.0.8           
## [43] proxy_0.4-27            stars_0.6-1             parallel_4.3.1         
## [46] s2_1.1.4                base64enc_0.1-3         vctrs_0.6.3            
## [49] webshot_0.5.4           jsonlite_1.8.5          bookdown_0.34          
## [52] hms_1.1.3               bit64_4.0.5             crosstalk_1.2.0        
## [55] jquerylib_0.1.4         units_0.8-2             glue_1.6.2             
## [58] lwgeom_0.2-13           leaflet.providers_1.9.0 codetools_0.2-19       
## [61] stringi_1.7.12          gtable_0.3.3            raster_3.6-20          
## [64] munsell_0.5.0           pillar_1.9.0            htmltools_0.5.5        
## [67] satellite_1.0.4         R6_2.5.1                wk_0.7.3               
## [70] sfheaders_0.4.3         vroom_1.6.3             evaluate_0.21          
## [73] lattice_0.21-8          highr_0.10              png_0.1-8              
## [76] bslib_0.5.0             class_7.3-22            Rcpp_1.0.10            
## [79] xfun_0.39               pkgconfig_2.0.3