Geospatial visualization
Introduction to geospatial visualization
Geospatial visualizations are one of the earliest forms of information visualizations. They were used historically for navigation and were essential tools before the modern technological era of humanity. Data maps were first popularized in the seventeenth century and have grown in complexity and detail since then.
Drawing raster maps with ggmap
library(tidyverse) library(ggmap) library(RColorBrewer) library(patchwork) library(here) options(digits = 3) set.seed(1234) theme_set(theme_minimal()) ggmap is a package for R that retrieves raster map tiles from online mapping services like Stamen Maps and plots them using the ggplot2 framework.
Practice drawing raster maps
library(tidyverse) library(ggmap) library(here) options(digits = 3) set.seed(123) theme_set(theme_minimal()) Run the code below in your console to download this exercise as a set of R scripts. usethis::use_course("cis-ds/visualize-spatial-i") New York City 311 data New York City has an excellent data portal publishing a large volume of public records.
Importing spatial data files using sf
library(tidyverse) library(sf) library(here) options(digits = 3) set.seed(1234) theme_set(theme_minimal()) Rather than storing spatial data as raster image files which are not easily modifiable, we can instead store spatial data as vector files.
Drawing vector maps with simple features and ggplot2
library(tidyverse) library(sf) library(here) options(digits = 3) set.seed(1234) theme_set(theme_minimal()) Unlike raster image maps, vector maps require you to obtain spatial data files which contain detailed information necessary to draw all the components of a map (e.
Practice drawing vector maps
library(tidyverse) library(sf) library(tidycensus) library(colorspace) library(scales) # useful on MacOS to speed up rendering of geom_sf() objects if (!identical(getOption("bitmapType"), "cairo") && isTRUE(capabilities()[["cairo"]])) { options(bitmapType = "cairo") } options(digits = 3) set.seed(123) theme_set(theme_minimal()) Run the code below in your console to download this exercise as a set of R scripts.
Selecting optimal color palettes
library(tidyverse) library(sf) library(tidycensus) library(RColorBrewer) library(patchwork) # useful on MacOS to speed up rendering of geom_sf() objects if (!identical(getOption("bitmapType"), "cairo") && isTRUE(capabilities()[["cairo"]])) { options(bitmapType = "cairo") } options(digits = 3) set.seed(1234) theme_set(theme_minimal()) Selection of your color palette is perhaps the most important decision to make when drawing a choropleth.