The Campaign Financing War 07/27/2014 : Part II
library(plyr) # for count,arrange
library(lattice) # for barchart
DJE <- read.csv("DE.07.27.2014.csv", stringsAsFactors = FALSE,skip=4)
SMF <- read.csv("SF.07.27.2014.csv", stringsAsFactors = FALSE,skip=4)
VKB <- read.csv("VB.07.27.2014.csv", stringsAsFactors = FALSE,skip=4)
JM <- read.csv("JM.07.27.2014.csv", stringsAsFactors = FALSE,skip=4)
SS <- read.csv("SS.07.27.2014.csv", stringsAsFactors = FALSE,skip=4)
LVW <- read.csv("LV.07.27.2014.csv", stringsAsFactors = FALSE,skip=4)
WDK <- read.csv("WK.07.27.2014.csv", stringsAsFactors = FALSE,skip=4)
# mtext("2014 42 LD Contributions to 07.27.2014: Democrats in Blue")
# After the function below ('jpeg_create') is finished running 'graphics.off()' needs to be run before the files write to disk at 'getwd()'. I then batch rename all the time stamped based files ('systime <- as.numeric(Sys.time())') to have the jpg suffix.
jpeg_create <- function() {
systime <- as.numeric(Sys.time())
# dev.new()
jpeg(filename = systime,
width = 1024, height = 768, units = "px", pointsize = 12,
quality = 100, bg = "white", res = NA, family = "", restoreConsole = TRUE,
type = c("windows"))
Sys.sleep(2)
}
jpeg_create()
par(mfrow=c(1,1))
plot(sort(c(DJE$Amount,VKB$Amount,LVW$Amount,WDK$Amount)),type="h",col=rgb(.9,0,0,0.3),ylab="$ Donations",xlab="",ylim=c(0,1150))
lines(sort(c(SMF$Amount,SS$Amount,JM$Amount)),type="h",col=rgb(0,0,.9,0.3),ylim=c(0,1150))
mtext("42nd LD Republicans vs. Democrats: Donations reported 07/27/2014",side=3,outer=TRUE,line=-1)
mtext(sum(SMF$Amount,SS$Amount,JM$Amount),side=1,outer=TRUE,line=-1)
mtext(sum(DJE$Amount,VKB$Amount,LVW$Amount,WDK$Amount),side=1,outer=TRUE,line=-2)
jpeg_create()
par(mfrow=c(2,1))
plot(sort(DJE$Amount),type="h",col="red",xlab=sum(DJE$Amount),ylab="Ericksen")
plot(sort(SMF$Amount),type="h",col="blue",xlab=sum(SMF$Amount),ylab="Fleetwood")
mtext("Ericksen vs. Fleetwood",side=3,outer=TRUE,line=-1)
jpeg_create()
par(mfrow=c(1,1))
plot(sort(DJE$Amount),type="h",col=rgb(.9,0,0,0.3),xlim=c(0,800),ylim=c(0,1150),xlab="",ylab="")
par(new=t)
plot(sort(SMF$Amount),type="h",col=rgb(0,0,.9,0.3),xlim=c(0,800),ylim=c(0,1150),xlab="Number of Donations",ylab="Donation Amount")
par(new=F)
mtext("Ericksen (red) vs. Fleetwood (blue): Donations reported 07/27/2014",side=3,line=2)
mtext(sum(DJE$Amount),side=3,line=1)
mtext(sum(SMF$Amount),side=3,line=0)
par(mfrow=c(1,1))
jpeg_create()
barchart(c(SMF$City),xlab="Fleetwood Donations by City",col="blue")
jpeg_create()
barchart(c(DJE$City),xlab="Ericksen Donations by City",col="red")
jpeg_create()
par(mfrow=c(2,1))
plot(sort(LVW$Amount),type="h",col="red",xlab=sum(LVW$Amount),ylab="Van Werven")
plot(sort(SS$Amount),type="h",col="blue",xlab=sum(SS$Amount),ylab="Satpal")
mtext("Van Werven vs. Satpal",side=3,outer=TRUE,line=-1)
jpeg_create()
par(mfrow=c(1,1))
plot(sort(LVW$Amount),type="h",col=rgb(.9,0,0,0.3),xlim=c(0,300),ylim=c(0,1150),xlab="",ylab="")
par(new=t)
plot(sort(SS$Amount),type="h",col=rgb(0,0,.9,0.3),xlim=c(0,300),ylim=c(0,1150),xlab="Number of Donations",ylab="Donation Amount")
par(new=F)
mtext("Van Werven (red) vs. Satpal(blue): Donations reported 07/27/2014",side=3,line=2)
mtext(sum(LVW$Amount),side=3,line=1)
mtext(sum(SS$Amount),side=3,line=0)
par(mfrow=c(1,1))
jpeg_create()
barchart(c(LVW$City),xlab="Van Werven Donations by City",col="red")
jpeg_create()
barchart(c(SS$City),xlab="Satpal Donations by City",col="blue")
jpeg_create()
par(mfrow=c(2,1))
plot(sort(VKB$Amount),type="h",col="red",xlab=sum(VKB$Amount),ylab="Buys")
plot(sort(JM$Amount),type="h",col="blue",xlab=sum(JM$Amount),ylab="Monjure")
mtext("Buys vs. Monjure",side=3,outer=TRUE,line=-1)
jpeg_create()
par(mfrow=c(2,1))
plot(sort(WDK$Amount),type="h",col="red", xlab=sum(WDK$Amount),ylab="Knutzen")
plot(sort(SS$Amount),type="h",col="blue",xlab=sum(SS$Amount),ylab="Satpal")
mtext("Knutzen vs. Satpal",side=3,outer=TRUE,line=-1)
par(mfrow=c(1,1))
jpeg_create()
barchart(c(SMF$City,SS$City,JM$City),xlab="Democratic Donations by City",col="blue")
jpeg_create()
barchart(c(DJE$City,VKB$City,LVW$City,WDK$City),xlab="Republican Donations by City",col="red")
Repub <- as.data.frame(rbind(DJE,VKB,LVW,WDK))
Demos <- as.data.frame(rbind(SMF,SS,JM))
Repub_ALL <- arrange(count(c(Repub$Amount)),desc(freq))
Demos_ALL <- arrange(count(c(Demos$Amount)),desc(freq))
Repub_NS <- arrange(count(subset(Repub, State != " WA", select=Amount)),desc(freq))
Demos_NS <- arrange(count(subset(Demos, State != " WA", select=Amount)),desc(freq))
jpeg_create()
par(mfrow=c(1,2))
qqplot(Demos_ALL$x,Demos_ALL$freq,type="b",ylim=c(0,100),xlab="",ylab="",col="blue",cex=2)
qqplot(Repub_ALL$x,Repub_ALL$freq,type="b",ylim=c(0,100),xlab="",ylab="",col="red",cex=2)
mtext("42nd LD Democrats (blue) vs. Republicans: All Donations",side=3,outer=TRUE,line=-1)
mtext("Quantile Plot: Frequency vs. Donation Size",side=3,outer=TRUE,line=-2)
jpeg_create()
par(mfrow=c(1,2))
qqplot(Demos_NS$Amount,Demos_NS$freq,type="b",ylim=c(0,20),xlab="",ylab="",col="blue",cex=2)
qqplot(Repub_NS$Amount,Repub_NS$freq,type="b",ylim=c(0,20),xlab="",ylab="",col="red",cex=2)
mtext("42nd LD Democrats (blue) vs. Republicans: Out of State Donations",side=3,outer=TRUE,line=-1)
mtext("Quantile Plot: Frequency vs. Donation Size",side=3,outer=TRUE,line=-2)
No comments:
Post a Comment