Navigating & Mapping with the ACS Package

Update: I added an adjusted graphic of all the states to represent the data overall not bracket by bracket.

This is a tutorial on accessing the ACS data, utilizing the acs package in R. Then using generated map data to create a nice heatmap of income diversity throughout the counties in Nebraska and with the help of ggplot2 and dplyr we are able visualize the data we gather.


Start by using the maps package to make a data frame of Nebraska. Then before accessing the ACS data you’ll need to request and API key from this ACS request form.

Once that is done we then access the ACS data we want, there is most assuredly a more elegant way to do this piece but this works… I found pieces I needed from the wonderfully helpful Intro to Viridis and a bit of the data wrangling from this tutorial.

Next we need to clean the data so we can merge it with our map data.

Calculate the percentage of households in Nebraska over $100k & plot!


A bit more

As the title image shows, I wanted to take this fairly simple visualization and process just a bit further. There are tons of levels to income in the ACS data, so what if we want to make a lot of graphs, for each level. We can add a few ggplot items, geoms, to make our plot look a little better. Using a ggtheme, theme_tufte, we can also remove some of those pesky grid lines, background color etc. You will also need to instantiate a couple new packages to get this to work, namely the viridis package for the color scheme, and extrafont to load the ‘American Typewriter’ font for the charts.

abcGreat, now that we have the template looking pretty spiffy let’s seem them all put together. I have put multiple plots on a single page in a couple different tutorials, the Twitter sentiment comparison, or in the tutorial where I first demonstrated the process. The idea is to facet the data out to avoid just representing  high population areas, as expertly explained by this XKCD comic. Putting it all together looks a little something like this. (Darker = higher %)


Below is the complete code to copy/paste and run to achieve the viridis styled graph. If you have ideas to streamline/improve any pieces please let me know! It works but I know it can be improved.