Skip to content

Instantly share code, notes, and snippets.

@smach
Created November 12, 2016 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smach/cb0c367c201e26793028d05a8bf7eb3d to your computer and use it in GitHub Desktop.
Save smach/cb0c367c201e26793028d05a8bf7eb3d to your computer and use it in GitHub Desktop.
---
title: ''
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
mydata <- read.csv("https://gist.githubusercontent.com/smach/9cc166277488d2499e208d2076ff26c3/raw/e2f596ce6a134657e4daa73550510f6fb949890b/MAEarlyVotingData.csv", stringsAsFactors = FALSE)
mydata <- subset(mydata, RegisteredVoters >= 30000)
library(ggplot2)
library(ggiraph)
library(dplyr)
mydata$tooltiptext <- paste0("<strong>", mydata$Place, "</strong><br />", mydata$TotalNonBusiness, " hours")
```
<center><h2>Access to Massachusetts early voting varies widely</h2></center>
by Sharon Machlis
Live in Brookline? You could choose from 24 hours of early voting outside of regular business hours. Brookline's early-voting schedule features evening hours Monday-Thursday and a full 8 hours on Saturday.
Live in Framingham, which has roughly the same number of registered voters? There are _no_ evening early-voting hours during the week and just 5 hours on Saturday.
In many US states that offer early voting, access varies by county. In Massachusetts, it's considerably more varied. While communities must have at least one polling site open during business hours in the Oct. 24 - Nov. 4 early voting period, beyond that, each community decides what to do. Cities and towns can add as many polling places and evening/weekend hours as they want -- or none at all.
I looked at schedules in all communities with at least 30,000 registered voters, and I discovered that access to off-business-hours early voting varies wildly, as you can see from the graph below. I focused on evening (which I defined as after 6 pm) and weekend hours, because for most people with fulltime 9-to-5 jobs and commutes, early voting during regular business hours doesn't help much. I also added time before 8 am as non-business hours.
Mouse over the bar graph to see community name and number of non-business-hours of early voting.
_Note: For details on a town's specific locations and hours, see the [Massachusetts Secretary of State website](http://www.sec.state.ma.us/EarlyVotingWeb/). I have tried to be as accurate as possible in this analysis, but as this is a personal project, I did not have an editor. And as we often say in the Computerworld newsroom, "Everyone needs an editor!"_
<center><h3>Early Voting Hours Before 8am, After 6pm and on Weekends</h3></center>
```{r graph_nitesweekends}
# Code adapted from an R Graphics Cookbook recipe, by Winston Chang
nitesweekends <- ggplot(mydata, aes(x=reorder(Place, -TotalNonBusiness), y=TotalNonBusiness)) +
geom_bar(stat="identity", color = "black", fill="#0072B2") +
# ggtitle("Early Voting Hours Before 8am, After 6pm and on Weekends") +
xlab("Place") +
ylab("Hours") +
theme_classic() +
# geom_text(aes(label=TotalNonBusiness), vjust=1.5, colour="white", position=position_dodge(.9), size=5) +
theme(plot.title=element_text(size=20)) +
theme(axis.text.x= element_text(angle=45, hjust = 1.3, vjust = 1.2))
gg_nitesweekends <- nitesweekends + geom_bar_interactive(aes(tooltip = tooltiptext), size = 0.5, stat="identity", color = "black", fill="#0072B2")
ggiraph(code = print(gg_nitesweekends))
```
I'd expect communities with more registered voters to have more resources, but that's not always the case. The scatterplot below shows evening/weekend hours compared with number of voters.
<center><h3>Early Voting Hours Compared with Number of Registered Voters</h3></center>
```{r myscatterplot}
library(taucharts)
tauchart(mydata) %>%
tau_point("RegisteredVoters", "TotalNonBusiness") %>%
tau_guide_x(label="") %>%
tau_guide_y(label="") %>%
tau_tooltip(c("Place", "TotalNonBusiness", "TotalAMHours", "TotalEveningHours", "SaturdayHours", "SundayHours","NumLocations", "RegisteredVoters")) # %>%
# tau_title("Early Voting Hours Compared with Number of Registered Voters")
```
<center><h3>Non-Business-Hours Early Voting Availability</h3></center>
You can see all the summarized data below. Lowell has the most evening and weekend early-voting hours, followed by Worcester, Newton, Brookline and Somerville.
```{r mydatatable, echo=FALSE}
library(DT)
options(DT.options = list(pageLength = 30))
datatable(mydata[,c("Place", "RegisteredVoters", "TotalNonBusiness", "TotalAMHours", "TotalEveningHours", "SaturdayHours", "SundayHours","NumLocations")], rownames=FALSE, options = list(
order = list(list(2, 'desc'))
)) %>%
formatCurrency('RegisteredVoters',currency = "", interval = 3, mark = ",", digits=0)
```
<center><h3>Voters and Square Miles per Early-Voting Location</h3></center>
Not surprisingly, Boston has the most early-voting polling locations -- but it's also by far the largest city in Boston. Here's a look at number of registered voters by early-voting polling location, and also number of square miles per polling location.
All polling locations are not open on all days; in fact, Lowell has a number of early-voting places that are only available for one day each during the period.
```{r mydatatable2, echo=FALSE}
datatable(mydata[,c("Place", "VotersPerLocation", "SqMilesPerLocation",
"NumLocations")], rownames=FALSE, options = list(
order = list(list(1, 'asc'))
)) %>%
formatCurrency('VotersPerLocation',currency = "", interval = 3, mark = ",", digits=0)
```
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-20443577-1', 'auto');
ga('send', 'pageview');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment