1. Cartographic workflows with tigris and tidycensus
In this video, we'll cover how to put all of the skills you've acquired together into a coherent cartographic workflow. You'll be using data obtained from tidycensus and tigris to make a dot-density map of race and ethnicity for Washington, DC from the 2010 decennial Census.
2. Dot-density maps
Dot-density mapping is a popular way to represent the distribution of geographic data visually. The technique scatters dots within enumeration units, like Census tracts, proportional to some data value. When dots are colored by a category in the data, color blending shows areas of heterogeneity in contrast with single-colored areas.
3. Generating random dots with sf
In this lesson, you'll learn how to create a similar type of map using data obtained with tidycensus and ggplot2. In our example workflow, we use the st_sample() function in the sf package to generate random dots by Census tract for each of the four racial and ethnic groups where each dot will represent approximately 100 people from the 2010 Census.
4. Considerations for random dot generation
The way you complete this process has cartographic implications. In the first approach shown on the slide, we can use group_by() and then summarize() to combine dots representing the same group into "multipoint" geometries, which will ultimately speed up plotting significantly in ggplot2. The second approach is more time consuming; however, it ensures that dot layering will be random and not by group, which means that your map will avoid placing all dots of one category on top of the others.
5. Basic dot-density mapping with sf
We can make a basic dot-density map of our data with the plot method in sf. However, this map lacks any reference information which may make it difficult to interpret for viewers unfamiliar with Washington DC's geography. It is a good idea to supplement your mapping with ancillary layers, such as roadways and bodies of water.
6. Ancillary data with tigris
The tigris package is an excellent resource for obtaining ancillary layers for mapping the United States in R. In this example, we get a roads dataset for DC, and filter for major road types; we also obtain an area water dataset for DC as well as the boundary of the district.
7. Ancillary data with tigris
Plotting DC's areal water features gives some insight into how these layers can be used to orient a map reader; as the Potomac River is prominent in Washington DC, it makes sense to incorporate this into your map to show the position of dots relative to the river and other water features.
8. Dot-density mapping with ggplot2
We can now put all of these layers together by using successive geom_sf() calls in ggplot2. When doing this, be mindful that ggplot2 plots the layers in order, so make sure your layer order is intentional. For example, we are plotting the water areas and roads after the dots here, which will avoid showing dots inside of water features and on roads in our map.
9. Dot-density mapping with ggplot2
Here we have our result. The ancillary layers provide important geographic context, and the small dot size we've used helps mitigate some of the issues with dot occlusion as we are using the layer that is faster to plot.
10. Considerations for dot-density mapping
When making dot-density maps, you should take a number of considerations into account. Viewers of dot-density maps sometimes assume that dots represent the exact location of individuals, so be clear that this is not the case with text on your map. Also note that some colors can blend to create other colors, potentially suggesting patterns that are not there if colors are not chosen carefully. Finally, take care with layer selection. Some reference is important, but too many layers can obscure your dots, which should remain prominent.
11. Let's practice!
Now, you'll create this dot-density map yourself with R and ggplot2!