Obtaining data for cartography with tigris
Before making your dot-density map of Washington, DC with ggplot2, it will be useful to acquire some ancillary cartographic data with the tigris package that will help map viewers understand what you've visualized. These datasets will include major roads in DC; area water features; and the boundary of the District of Columbia, which you'll use as a background in your map.
This exercise is part of the course
Analyzing US Census Data in R
Exercise instructions
- Get a roads dataset for Washington, DC with the
roads()
function, and filter the result for major roads in the District. - Use the
area_water()
function from tigris to get an area water features dataset. - Obtain the boundary of DC by using tigris's
counties()
function.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Filter the DC roads object for major roads only
dc_roads <- ___("DC", "District of Columbia") %>%
___(RTTYP %in% c("I", "S", "U"))
# Get an area water dataset for DC
dc_water <- ___("DC", "District of Columbia")
# Get the boundary of DC
dc_boundary <- ___("DC", cb = TRUE)