Corresponding political piece here.
# R 3.01 (plus sqldf and plyr packages)
require(sqldf)
require(plyr)
setwd("C:/Politics")
VDB_05.20.2014 <- read.delim("05.20.2014.txt")
VDB <- VDB_05.20.2014
as.matrix(names(VDB))
VDB_S <- VDB[,c(1,18,32:36)]
barplot(as.vector(arrange(count(VDB_05.20.2014$PrecinctID),desc(freq))[,2]),names.arg=(c(arrange(count(VDB_05.20.2014$PrecinctID),desc(freq))[,1])))
barplot(as.vector(arrange(count(VDB_05.20.2014$PrecinctPortion),desc(freq))[,2]),names.arg=(c(arrange(count(VDB_05.20.2014$PrecinctPortion),desc(freq))[,1])))
b_count1 <- (sqldf("Select PrecinctID,Count(BallotCounted_1) from VDB_S where BallotCounted_1 = 1 Group By PrecinctID Order By PrecinctID DESC"))
b_count2 <- (sqldf("Select PrecinctID,Count(BallotCounted_2) from VDB_S where BallotCounted_2 = 1 Group By PrecinctID Order By PrecinctID DESC"))
b_count3 <- (sqldf("Select PrecinctID,Count(BallotCounted_3) from VDB_S where BallotCounted_3 = 1 Group By PrecinctID Order By PrecinctID DESC"))
b_count4 <- (sqldf("Select PrecinctID,Count(BallotCounted_4) from VDB_S where BallotCounted_4 = 1 Group By PrecinctID Order By PrecinctID DESC"))
b_count5 <- (sqldf("Select PrecinctID,Count(BallotCounted_5) from VDB_S where BallotCounted_5 = 1 Group By PrecinctID Order By PrecinctID DESC"))
b_count1_ <- (sqldf("Select PrecinctID,Count(BallotCounted_1) from VDB_S where BallotCounted_1 = 0 Group By PrecinctID Order By PrecinctID DESC"))
b_count2_ <- (sqldf("Select PrecinctID,Count(BallotCounted_2) from VDB_S where BallotCounted_2 = 0 Group By PrecinctID Order By PrecinctID DESC"))
b_count3_ <- (sqldf("Select PrecinctID,Count(BallotCounted_3) from VDB_S where BallotCounted_3 = 0 Group By PrecinctID Order By PrecinctID DESC"))
b_count4_ <- (sqldf("Select PrecinctID,Count(BallotCounted_4) from VDB_S where BallotCounted_4 = 0 Group By PrecinctID Order By PrecinctID DESC"))
b_count5_ <- (sqldf("Select PrecinctID,Count(BallotCounted_5) from VDB_S where BallotCounted_5 = 0 Group By PrecinctID Order By PrecinctID DESC"))
par(mfrow=c(1,5))
plot(b_count5[,2] ~ b_count5[,1],type="h",col="brown",ylim=c(0,1000),xlab="2009",ylab="")
plot(b_count4[,2] ~ b_count4[,1],type="h",col="green",ylim=c(0,1000),xlab="2010",ylab="")
plot(b_count3[,2] ~ b_count3[,1],type="h",col="blue",ylim=c(0,1000),xlab="2011",ylab="")
plot(b_count2[,2] ~ b_count2[,1],type="h",col="red",ylim=c(0,1000),xlab="2012",ylab="")
plot(b_count1[,2] ~ b_count1[,1],type="h",col="black",ylim=c(0,1000),xlab="2013",ylab="")
mtext("Whatcom County General Elections 2009 - 2013 for voters active May 20 2014 only",side=3,outer=TRUE,line=-1.5)
mtext("Precincts",side=1,outer=TRUE,line=-1)
mtext("Votes Counted",side=2,outer=TRUE,line=-1.25)
par(mfrow=c(1,5))
plot(b_count5_[,2] ~ b_count5_[,1],type="h",col="brown",ylim=c(0,1000),xlab="2009",ylab="")
plot(b_count4_[,2] ~ b_count4_[,1],type="h",col="green",ylim=c(0,1000),xlab="2010",ylab="")
plot(b_count3_[,2] ~ b_count3_[,1],type="h",col="blue",ylim=c(0,1000),xlab="2011",ylab="")
plot(b_count2_[,2] ~ b_count2_[,1],type="h",col="red",ylim=c(0,1000),xlab="2012",ylab="")
plot(b_count1_[,2] ~ b_count1_[,1],type="h",col="black",ylim=c(0,1000),xlab="2013",ylab="")
mtext("Whatcom County General Elections 2009 - 2013 for voters active May 20 2014 only",side=3,outer=TRUE,line=-1.5)
mtext("Precincts",side=1,outer=TRUE,line=-1)
mtext("Votes Not Counted",side=2,outer=TRUE,line=-1.25)
par(mfrow=c(2,2))
plot(b_count2[,2] ~ b_count2[,1],type="h",col="red",ylim=c(0,1000),xlab="2012",ylab="")
plot(b_count2_[,2] ~ b_count2_[,1],type="h",col="red",ylim=c(0,1000),xlab="2012",ylab="")
plot(b_count1[,2] ~ b_count1[,1],type="h",col="black",ylim=c(0,1000),xlab="2013",ylab="")
plot(b_count1_[,2] ~ b_count1_[,1],type="h",col="black",ylim=c(0,1000),xlab="2013",ylab="")
mtext("Whatcom County General Elections 2012 - 2013 for voters active May 20 2014 only",side=3,outer=TRUE,line=-1.5)
mtext("<- Votes Counted Precincts Votes Not Counted ->",side=1,outer=TRUE,line=-1)
mtext("Votes Counted vs. Not Counted",side=2,outer=TRUE,line=-1.25)
par(mfrow=c(2,1))
plot((b_count2[,2] + b_count2_[,2]) ~ b_count2[,1],type="h",col="red",ylim=c(0,1000),xlab="2012",ylab="")
plot((b_count1[,2] + b_count1_[,2]) ~ b_count1[,1],type="h",col="black",ylim=c(0,1000),xlab="2013",ylab="")
mtext("Whatcom County General Elections 2012 - 2013 for voters active May 20 2014 only",side=3,outer=TRUE,line=-1.5)
mtext(" Precincts ",side=1,outer=TRUE,line=-1)
mtext("Votes Counted + Not Counted",side=2,outer=TRUE,line=-1.25)
b2012m <- b_count2[,2] + b_count2_[,2]
b2013m <- b_count1[,2] + b_count1_[,2]
Precinct <- b_count1$PrecinctID
C <- data.frame(cbind(Precinct,b2012m,b2013m))
D <- C$b2013m - C$b2012m
E <- data.frame(cbind(Precinct,D)
plot(E,type="h",ylab="Increase in active voters as of May 20,2014",xlab="Precincts for 2012 and 2013 general election" )
No comments:
Post a Comment