Unit 3: Maps and Geographic Data
This unit moves from tables and graphs to maps. It starts by making thematic maps in R with the tmap package, using campus data on UNC’s trees, sidewalks, and buildings. It then steps back from the code to ask how the real world becomes geographic data in the first place: the vector and raster data models, and the file formats that store them. Next comes location itself: how a datum, a coordinate system, and a map projection turn places on a round Earth into coordinates on a flat map. The unit ends by getting geographic data from the places that publish it: the US Census Bureau, through the APIs that let your code download its data directly, and the ArcGIS servers that publish many government GIS layers.
Chapter 10: Thematic Maps with tmap
A thematic map shows how one theme varies from place to place. This chapter reads spatial data into R as sf objects, which are tidy data frames with a geometry column, and maps points, lines, and polygons with tmap’s tm_shape(), tm_dots(), tm_lines(), and tm_polygons(). It covers coloring features by an attribute, choosing classes, combining layers, adding a title, scale bar, and north arrow, and switching between static and interactive maps.
Chapter 11: What Is Geographic Data?
Every map is a model of the world. This chapter follows data abstraction from real-world entities to features a computer can store, and compares the two main data models: vector data (points, lines, and polygons with attributes) and raster data (grids of cells). It explains map scale, cell size and resolution, and the common file formats (shapefile, GeoJSON, KML, and GeoTIFF), and why metadata matter.
Chapter 12: Location and Coordinate Systems
To store a location, a computer needs a model of the Earth, a grid on it, and a way to flatten it. This chapter covers geodesy and the ellipsoid, the datums used in North America (NAD27, NAD83, and WGS84), latitude and longitude, and converting between decimal degrees and degrees, minutes, and seconds. It explains why every map projection distorts shape, area, distance, or direction, how to choose one for a task, and how to check and change a layer’s coordinate reference system in R with st_crs() and st_transform().
Chapter 13: Census Data and APIs
US Census data come from the decennial census, a full count every ten years, and the American Community Survey, a continuous sample with a margin of error on every estimate. This chapter explains how Census geography nests from states down to tracts and blocks, how APIs work, and how the tidycensus package downloads tidy, map-ready Census data. It also shows how to carry margins of error through calculations and compare data across years.
Chapter 14: ArcGIS Data with arcpullr
Governments publish many of their GIS layers on ArcGIS REST services. This chapter shows how to find a layer’s URL and read its REST page, then download it into R as an sf object with arcpullr’s get_spatial_layer(). It covers SQL where clauses that download only the features you need, the server’s record limit, and the other ways arcpullr can query a layer.
install.packages(), then load it in
each session with library().
A sequence of values that R stores together, made with c(),
such as c(71, 75, 68).
Spatial data stored as a grid of cells (pixels), each holding a value,
such as a satellite image or an elevation model. In R, the
terra package handles rasters.
A model that fixes an ellipsoid to the real Earth, so that a latitude
and longitude point to one place on the ground. NAD83 and WGS84 are
datums.
The rules that tie coordinates to places on the Earth, including how the
round Earth is flattened onto a map (the projection). Layers must share
a coordinate system before you can combine them.
A method for flattening the curved graticule onto a flat map. Every
projection distorts shape, area, distance, or direction.
Application Programming Interface: a set of rules for how one program
asks another for data or services, such as your R script asking the
Census Bureau’s server for a table.
“Simple features”: the R package for spatial vector data. An sf object
is a data frame with a geometry column holding each row’s point, line,
or polygon.
R’s table: rows are observations and columns are variables. A tibble is
the tidyverse’s version of a data frame.
A closed shape that represents an area, such as a county, a lake, or a
census tract.
The level of detail at which you study something: addresses,
neighborhoods, counties, or states. A pattern that is clear at one scale
can vanish or reverse at another.
Spatial data stored as points, lines, and polygons, each with a table of
attributes. In R, the sf package handles vector data.
An open, plain-text format for vector features, written in JSON.
Coordinates are longitude first, then latitude, in WGS84.
Keyhole Markup Language: the XML-based format behind Google Earth. A
.kmz file is a zipped KML file.
The standard file format for raster data: a TIFF image with its location
and coordinate system stored inside the file.
Data about data: who made a dataset, when, how, and what each part
means. In a YAML header, it describes the document.
The science of measuring the Earth’s size, shape, orientation, and
gravity. Every coordinate rests on a geodetic model of the Earth.
A sphere flattened at the poles: the smooth mathematical shape used to
model the Earth, defined by its semi-major and semi-minor axes.
The North American Datum of 1927, based on the Clarke 1866 ellipsoid and
a single origin point in Kansas.
The North American Datum of 1983, based on the GRS80 ellipsoid and
maintained through a network of permanent GPS stations (CORS).
The World Geodetic System of 1984, the datum GPS uses. GeoJSON and KML
give coordinates as WGS84 longitude and latitude.
The angle north or south of the Equator, from 0° to 90°. Lines of equal
latitude are parallels.
The angle east or west of the Prime Meridian, from 0° to 180°. Lines of
equal longitude are meridians.
Coordinates written as signed decimal numbers, such as −79.05°. Negative
means south latitude or west longitude.
Coordinates written as whole degrees, minutes (1/60 of a degree), and
seconds (1/3,600 of a degree), with a letter N, S, E, or W, such as 79°
3′ 21″ W.
The full count of everyone in the US, every ten years. It asks only a
few questions but covers every person.
The Census Bureau’s continuous survey of a sample of households every
year. It asks many more questions than the decennial census, but every
value is an estimate with a margin of error.
A subset of a population that is surveyed to estimate something about
the whole population. Smaller samples give less certain estimates.
How far a sample estimate might be from the true value. ACS margins of
error use a 90% confidence level: there is a 90% chance the true value
lies within the estimate plus or minus the MOE.
A small area of about 1,200 to 8,000 people (4,000 on average), drawn to
be fairly stable over time. The workhorse unit for neighborhood
analysis.
An R package that downloads US Census data through the Census API and
returns it as a tidy data frame, with boundaries attached if you ask.
The most common style of web API: each dataset has its own URL, you ask
for data with ordinary web requests, and the answer usually comes back
as JSON.
An R package that downloads layers from ArcGIS REST services as sf
objects, with get_spatial_layer().
Structured Query Language, the language of databases. ArcGIS
where clauses use it: fcounty = 'Orange'.