With a major election coming next year, I was wondering if there have been any shifts & changes in the voters in my state. This seems like an interesting opportunity for some data analysis, eh!?!
To get you into the spirit of elections, here's an "I Voted" sticker from my friend Dee:
I've lived in North Carolina most all my life, and have seen it go through lots of changes as it shifted from being a textile & tobacco state, to being the Silicon Valley of the East Coast. With cities such as Raleigh, Apex, and Cary placing highly on national "best of" lists, and companies like SAS appearing on the "best places to work" lists, lots of new people have been moving to North Carolina from other states. I'm curious how these changes might affect voting preferences, and I thought a good place to start might be the voter registration data.
After a bit of searching I found the NC voter registration data online. Luckily the data was accessible through simple URLs and html pages (rather than an interactive system that lets you view the data through an interface, but just one url to the interface). For example, here is the page for the Jan 3, 2015 data. The data was not available in a simple format such as csv, but at least it was in straightforward html tables that I could write some SAS code to scrape the data from the web pages.
I first wrote some code to read in the most recent data, and plotted it on a map, in several different ways. I generated a choropleth map showing the main political party in each county, and then separate heat maps for each political party ... but the one I liked best was a custom map with a pie chart on each county. I expected the pies to show a 2-way split between Republicans and Democrats, but I was surprised to see it was a 3-way split with Unaffiliated being a significantly large slice.
The map was interesting, but I wondered how the political composition had changed over time. Therefore I enhanced my code to read in the data for each year, and generated a time series plot for each county. With 100 counties, it was a bit cumbersome to scroll through the entire list to find a certain county, therefore I set up html an anchor for each county, and added drill down links from the counties in the map to jump right to the time series plot of the clicked-on county. (Note that the first time you view the time series plots, it will need to cache all 100 county graphs to your browser, which is about 6.5MB. On my home computer, this took about 30 seconds. After they're all cached, your response time should be very quick!)How to build a customized voter registration data viewer #sastip Click To Tweet
Here is (non-interactive) snapshot for Mc Dowell county, for example:
I invite you to view the pie map, and click on several counties ... and then come up with theories about how & why the data has been changing (or not changing) over time. This will be a good warm-up for the upcoming elections!