Visualizing partisan trends using Santa Barbara County voter registration data
R
Data Visualization
Spatial Analysis
Political Data
Author
Leilanie Rubinstein
Published
March 17, 2025
Voter Registration Data Infographic
Why voter data?
Since childhood, I’ve been interested in politics– a fault I attribute to my dad. We were your typical liberal Prius-driving NPR listeners and CNN-blaring-in-the-background household. Upon moving to Santa Barbara in 2017 for my undergraduate degree, I’ve volunteered or worked in every election, traveling up and down the county to knock on doors for local candidates with pro-environment and pro-housing values.
Some campaigns over the years
Most visualizations of voter data happen at the national or state level, rather than within counties. Furthermore, election data from the 2024 general election has not been fully certified yet for most counties in California. I aim to provide a quick overview of the political composition of our county using voter registration and census data for people interested in local politics. A few questions I’d like to answer include:
How are Democratic and Republican voters spatially distributed throughout the county?
What is the political composition of the county?
Is there a partisan difference between voter ages?
How do voter registrations change over time? Do they increase in frequency closer to elections?
About the data
The Santa Barbara County voter registration data used for this project was requested from SB County Elections, and is dated for May 9, 2025. It contains voter registration information (voter name, address, contact information, voting precinct, and political party affiliation) for all voters in the county.
For census data, I use the tidycensus and tigris packages, with 2020 and 2023 geometries and population surveys, and tidygeocoder for addresses.
Visualizations
How are voters distributed across the county? I wanted to plot the difference in percentage of Democrats compared to Republicans across the county. I chose a chloropleth map to visualize this, because it is a good way to display spatial relationships. In Santa Barbara, urban centers in South County tend to lean heavily Democratic, while more rural areas are Republican. One challenge with displaying partisanship on a chloropleth map, however, is the visual overrepresentation of sparsely populated but large geographic areas. It appears as though a large portion of the county is red, when in reality very few people live in those areas, and the county as a whole leans solidly Democratic. Census blocks tend to be smaller than tracts, and areas with no population were excluded, therefore lessening the visual effect of area.
What is the partisan breakdown of the county? I’ve included a waffle plot displaying the proportion of voters by party to visualize the percentage of voters belonging to each political party.
How old are Democrats vs. Republicans? For this visualization, I chose stacked bar charts to visualize the age breakdowns within each party and across the county. On average, Democrats are slightly younger than Republicans.
When do people register to vote? Voters generally register to vote closer to elections, and we can see that there is a noticeable spike in the line graph of number of registrations each general election year (labeled on the x-axis). When we look at the weekly and daily registration trends leading up to the 2024 general election, we see a spike in registrations around the registration deadline and on election day.
Code for Visualizations
Show code
# -------------- Setup --------------# Load packageslibrary(tidyverse)library(janitor)library(here)library(tidycensus)library(ggmap)library(sf)library(tigris)library(showtext)library(sysfonts)library(tidygeocoder)library(tmap)library(tmaptools)library(waffle)library(patchwork)library(leaflet)# Set census API keycensus_api_key(Sys.getenv("CENSUS_API_KEY"))
# Create a bounding box for a zoomed-in look at south countysouth_county_bbox <- tigris::places(state ="CA", cb =TRUE) %>%filter( NAME %in%c("Santa Barbara","Goleta","Carpinteria","Isla Vista","Summerland","Montecito","Eastern Goleta Valley","Mission Canyon","University of California-Santa Barbara","Toro Canyon" ) ) %>%st_union() %>%st_buffer(dist =0.02)