Created
February 8, 2012 13:59
-
-
Save gka/1769733 to your computer and use it in GitHub Desktop.
Contributions per Candidate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# read csv file | |
ds <- read.csv('2012-Presidential-Campaign-Finance-Contributors.tsv', sep='\t') | |
# aggregate by candidate | |
res <- aggregate(ds$contb_receipt_amt, by=list(ds$cand_nm), FUN=sum, na.rm=TRUE) | |
X = data.frame(name=res$Group.1, amount=res$x) | |
# make data columns callable without typing X$ everytime | |
attach(X) | |
# sort dataset by amount | |
X <- X[order(amount),] | |
# assign party and colors | |
X$party[name == "Obama, Barack"] <- "Democrats" | |
X$color[name == "Obama, Barack"] <- "#2255EE" | |
X$party[name != "Obama, Barack"] <- "Republicans" | |
X$color[name != "Obama, Barack"] <- "#EE2244" | |
X$party <- factor(X$party) | |
# create a nicer labels like "Obama, Barack ($123.4 mio)" | |
X$labels <- sprintf("%s ($%.1f mio)", name, amount/1000000) | |
detach(X) | |
attach(X) | |
# output dot chart | |
dotchart(amount/1000000, labels=labels, color=color, groups=party, | |
main="Contributions per Candidate", xlab="Amounts in Mio $", pch=19, cex=.8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think I found it here
http://datahub.io/dataset/us-presidential-campaign-finance-2012-contributors@2012-02-04T18%3A12%3A57.428484