CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Analyzing US Census Data in R

Afficher le cours

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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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)
Modifier et exécuter le code