LoslegenKostenlos loslegen

Faceted maps with ggplot2

One of the most powerful features of ggplot2 is its support for faceted plotting, in which multiple plots are generated for unique values of a column in the data. Faceted maps can be produced with geom_sf() in this way as well if tidycensus data are in tidy format. In this exercise, you'll produce faceted maps that show the racial and ethnic geography of Washington, DC from the 2010 decennial Census.

Diese Übung ist Teil des Kurses

Analyzing US Census Data in R

Kurs anzeigen

Anleitung zur Übung

  • Check the first few rows of the pre-loaded dc_race dataset to view its structure.
  • Set the datum to NA to remove gridlines behind the maps.
  • Use facet_wrap() to create separate maps for unique values in the variable column of your dataset.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Check the first few rows of the loaded dataset dc_race
head(___)

# Remove the gridlines and generate faceted maps
___(___, aes(fill = percent, color = percent)) + 
  ___() + 
  coord_sf(___ = NA) + 
  ___(~variable)
Code bearbeiten und ausführen