# Re-mapping Massachusetts Special election results

January 27, 2010
By

(This article was first published on Offensive Politics » R, and kindly contributed to R-bloggers)

I had previously posted maps showing the difference in major party vote share between the 2008 Presidential election and the 2010 special Senate election in Massachusetts. Colleagues and readers of the Revolutions blog had some very insightful criticisms of these maps, in particular that the color scale was over-stating the swing in voter sentiment. I’ve decided to perform the process again, taking some of their advice into account, and hopefully producing more useful output in the process.

One concern was my using arbitrary-sized bins for the range comparison. Revo blog commenter Mike Lawrence suggested 3 equal sized bins with a neutral color for near zero values. Given the variance in election returns between townships (sd=28 points in 2010,sd=20 in 2008) I’m going to choose 10 bins instead of 3, but otherwise this is an excellent suggestion. Initially we’ll be measuring the difference between the Republican and Democratic vote percentage in each township for the 2008 and 2010 elections. This tells us not only which party won, but by how much.

Here is the code to recreate the MA 2010 senate returns map with breaks of 15% and a different color palette showing neutral middle colors.

 library(maptools) library(sp) library(Hmisc)   labels = c("54-70% Dem","41-55% Dem","26-40% Dem","11-25% Dem","0-10% Dem","0-10% Rep","10-24% Rep","25-39% Rep","40-54% Rep","55-70% Rep") cuts=c(-.7,-.55,-.4,-.25,-.1,0,.1,.25,.4,.55,.70)   masen <- read.csv('masen2010.csv') masen\$Total <- masen\$GOP + masen\$DEM + masen\$LIB masen\$Offset <- (masen\$GOP - masen\$DEM) / masen\$Total shp <- readShapeSpatial('tl_2009_25_cousub') shpA <- shp[match(masen\$place,shp\$NAME),] masen\$Col1 <-cut2(masen\$Offset,cuts=cuts) colors <- rev(brewer.pal('RdYlBu',n=10)) plot(shpA,col=colors[as.integer(masen\$Col1)],border=grey(.85)) title("Major Party Winning Vote Percentage MA Sen 2010") legend("bottomleft", legend=labels,fill=colors)

Which gives us the following output:

I believe this map more accurately represents the results. As a companion to the 2010 major party results I’d like to recreate the 2008 presidential results, using the same scale and bins.

 gen2008 <- read.csv('mapg2008.csv') gen2008\$Offset <- (gen2008\$rep - gen2008\$dem)/ gen2008\$total gen2008\$Col1 <- cut2(gen2008\$Offset,cuts=cuts) shpA <- shp[match(gen2008\$place, shp\$NAME),] plot(shpA,col=colors[as.integer(gen2008\$Col1)],border=grey(.85)) legend("bottomleft",legend=labels,fill=colors) title("Major party win percentage MA Presidential 2008")

Now the two graphs can more or less be compared apples to apples, and we can draw some very interesting conclusions from that comparison. The nine townships that were heavily democratic in 2008 actually stayed heavily Democratic in 2010, white most all other townships showed an increase in Republican support. These townships didn’t necessarily flip from being won by a Democrat to being won by a Republican, but every township showed an increase.

The least successful map I had previously produced was attempting to illustrate the degree of increased Republican support. What I really wanted to show was the increase in Republican support between the elections 2008 and 2010 elections.

 masen <- masen[order(masen\$place),] magen <- gen2008[order(gen2008\$place),] masen\$RepP <- (masen\$GOP / masen\$Total)*100 magen\$RepP <- (magen\$rep / magen\$total)*100 gain <- masen\$RepP - magen\$RepP gr <- cut2(gain,cuts=seq(0,30,by=5)) colors <- brewer.pal("Reds",n=6) shpA <- shp[match(magen\$place,shp\$NAME),] plot(shpA,col=colors[as.integer(gr)]) title("Increase in Republican vote percentage 2008 to 2010") legend("bottomleft",legend=c("0-4%","5-9%","10-14%","15-19%","20-24%","25-30%"),fill=colors)

From this map we can see that from 2008 to 2010 the Republican vote percentage actually increased in every single township in MA. This is kind of shocking, especially when you consider that Democrats enjoy a 15 point registration advantage statewide(source: warning PDF). If I were a campaign manager for Richard Neal (2nd Cd) or Jim McGovern (3rd CD) I’d take a long look at what the Coakley campaign did to so many democratic voters to either stay home or cross party lines in the 2010 special election.

jjh

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...