# Show Missouri registered voters with census population. # Franklin Center for Government & Public Integrity # Earl F Glynn # 28 July 2012 ################################################################################ ### Setup # Common functions to read/plot voting age census data by county source("F:/US-Census/Voting-Age-Population/Census-Voting-Age-Population.R") setwd("F:/Voter-Registration/Missouri/Census-Registration-Comparison/") ################################################################################ ### Missouri county plotting callback function to plot voter registration # data known globally plot.missouri.registration <- function(county) { county.name <- county # Remove "County" from census county name to match registration data, # except for St Louis County (there is also a St. Louis city) if (county.name != "St. Louis County") # has a period when invoked here { county.name <- gsub(" County","", county.name) } # Remove periods in all "St." and "Ste." names for match to work. county.name <- gsub("\\.", "", county.name) # Missouri breaks Jackson County into Kansas City and the rest of Jackson County. # Since the US Census does not do this, let's aggregate Missouri voter data to # compare with Census. if (county.name == "Jackson") { mtext("(Includes Kansas City election district)", line=-1, col="blue") } # Online data points(dates.total, voters.total[county.name,], pch=3, cex=1.25, col="red") points(dates.active, voters.active[county.name,], pch=4, cex=1.25, col="green") # Voter file data points(voter.file.dates.total, voter.file.total[county.name,], pch=1, col="red") points(voter.file.dates.active, voter.file.active[county.name,], pch=2, col="green") mtext(" Sources: U.S. Census; Missouri Secretary of State", BOTTOM<-1, adj=0, line=-1, cex=0.75, col="blue", outer=TRUE) legend("bottom", c("Online Reported Total Registration", "Voter File Total Registration", "Online Reported 'Active' Voters", "Voter File 'Active' Voters"), title="Registered Voters", pch=c(3, 1, 4, 2), text.col=c("red", "red", "green", "green"), col=c("red","red","green","green"), box.lty="blank") } ################################################################################ ### Read Missouri Registered Voter data ### Remember: Need to have rowname of total line "TOTAL" for use in callback # Data from Missouri Secretary of State's web site filename <- paste("F:/Voter-Registration/Missouri/", "Census-Registration-Comparison/SOS-Data/", "Missouri-County-Voter-Counts-2000-2010-Stats-Active.csv", sep="") voters.active <- read.csv(filename, row.names=1) filename <- paste("F:/Voter-Registration/Missouri/", "Census-Registration-Comparison/SOS-Data/", "Missouri-County-Voter-Counts-2000-2010-Stats-Total.csv", sep="") voters.total <- read.csv(filename, row.names=1) # FIXUP to add Kansas City's data to Jackson County voters.active["Jackson",] <- voters.active["Jackson",] + voters.active["Kansas City",] voters.total["Jackson",] <- voters.total["Jackson",] + voters.total["Kansas City",] # Change column headings Dyyyy.mm.dd to dates. dates.active <- as.Date(gsub("\\.","-",gsub("D","", colnames(voters.active)))) dates.total <- as.Date(gsub("\\.","-",gsub("D","", colnames(voters.total )))) stopifnot( all(dates.active == dates.total) ) # Voter File Data filename <- paste("F:/Voter-Registration/Missouri/", "Census-Registration-Comparison/Voter-Files/", "Missouri-County-Voter-Counts-2004-2012-Files-Active.csv", sep="") voter.file.active <- read.csv(filename, as.is=TRUE, row.names=1) filename <- paste("F:/Voter-Registration/Missouri/", "Census-Registration-Comparison/Voter-Files/", "Missouri-County-Voter-Counts-2004-2012-Files-Total.csv", sep="") voter.file.total <- read.csv(filename, as.is=TRUE, row.names=1) # FIXUP to add Kansas City's data to Jackson County voter.file.active["Jackson",] <- voter.file.active["Jackson",] + voter.file.active["Kansas City",] voter.file.total["Jackson",] <- voter.file.total["Jackson",] + voter.file.total["Kansas City",] # Change column headings Dyyyy.mm.dd to dates. voter.file.dates.active <- as.Date(gsub("\\.","-",gsub("D","", colnames(voter.file.active)))) voter.file.dates.total <- as.Date(gsub("\\.","-",gsub("D","", colnames(voter.file.total )))) stopifnot( all(voter.file.dates.active == voter.file.dates.total) ) ################################################################################ ### Plot Missouri census and voter registration data by county. # Missouri FIPS code is "29" d <- get.voting.age.census.data("29") cat(d$state, "\n") # verify we have the correct state # IGNORE this usual check since voter data has "Kansas City" district that # is not in usual U.S. Census data for counties. # Verify County names from census match county names of voter counts # stopifnot( all( gsub(" County","",d$counties) == rownames(voters.active) ) ) # Write census data file # Add actual dates instead of only year index before writing file d$census.data$Date <- d$timeline[d$census.data$Year] write.csv(d$census.data[,c("State", "County", "Year", "Date", "Population", "VotingAge")], paste(gsub(" ","-",d$state), "-Voting-Age-Population.csv", sep=""), row.names=FALSE) # Plot all counties in PDF file pdf(paste(gsub(" ","-",d$state), # Change blanks to dashes in state names "-Voting-Age-Population-and-Registered-Voters.pdf", sep=""), width=8, height=8) plot.county.population.charts(d$state, d$counties, d$census.data, d$timeline, plot.missouri.registration) dev.off()