This project aims to collect data about Framingham, Massachusetts and wrangle it so it is in a form useful for analysis. It focuses largely on election results for now – more specifically local mayoral and City Council races as well as turnout information – but there are other files here such as precinct shapefiles and property records.
See a searchable table of available data files below. If you know regular expressions, those work in the search and filter boxes.
Election data is in one of two structures – “tidy”, sometimes called “long”, with one observation in each row; or more human-readable format, with multiple data points per row. Tidy election data files are in the data/elections/tidy subdirectory.
If you are doing analysis in R and other platforms (including as a basis for Excel pivot tables), tidy format is more useful. If you want to combine data sets, tidy is definitely more useful since most tidy data sets have the same column names: Candidate, District or Precinct, Votes, Race, Year, Election.
If you are just looking to see results, the non-tidy format will likely be more useful. Those files are in the data/elections directory.
The data generally start in 2017 with Framingham’s transition from town to city form of government, although I have a few raw data files from earlier elections. I do not include preliminary elections unless they are city-wide.
Source: Local election data generally come from PDFs of results provided by the Framingham City Clerk’s office. I then extract data from PDF into Excel files using the CometDocs cloud service or PDF Tables and do a fair amount of data wrangling on those results.
GIS shapefiles for Framigham precincts. data/gis/Framingham_Districts_and_Precincts_2018.zip contains official shapefiles pre-2020 Census, which I downloaded from Framingham Open Data. There are also precinct files emailed to me by Geoffrey W. Kovar, Framingham GIS Manager, via email on July 14, 2017 and a new file of proposed post-2020-Census precincts.
GIS shapefiles for all Framingham parcels, downloaded from Open Data Framingham
CSV file of which district each precinct belongs to.
Some R files used to wrangle and analyze data.
Election data in human-friendly format is in the data/elections directory. Election data in analysis-friendly tidy format is in the data/elections/tidy subdirectory. Original election-result PDFs from the City Clerk’s office as well as Excel files created from those PDFs via CometDocs are in the data-raw/elections subdirectory.
GIS files and maps, such as precinct and district shapefiles, are in the data/gis subdirectory.
R code to generate maps from the GIS files are in the R subdirectory.
Property valuations are in the data/property subdirectory.
Some of the R files I used to reshape the data are in the R
directory. In addition, the config.R file loads necessary
packages for running the other files. And, get_turnouts.R
generates a tidy data frame of all available election turnout data by
precinct, stored in an R object called all_turnout_data
.
R/framingham_basemap.R
creates a map of Framingham precincts, colored by district and
searchable by address, using the R leaflet package.
The CSV of which Framingham precincts make up each district is in the data directory.
R users: You can read shapefiles into R with the sf package, such as
These are some of the scripts I used to turn raw data into analysis-friendly data:
R/election_general_2017_framingham.R – R file to convert November 2017 official results spreadsheet to an analysis-friendly format.
R/election_preliminary_2017_framingham.R – R file to convert September 2017 official results spreadsheet to an analysis-friendly format.
R/election_charter_2017.R – R file to convert April 2017 city charter results to analysis-friendly format.
R/election_general_2019.R – R file to convert November 2017 official results data to an analysis-friendly format.
R/election_helpers.R – file with some useful functions for working with Framingham election data.
R/election_preliminary_2021_framingham.R – R file to process September 2021 election data.