Created
April 24, 2013 19:49
-
-
Save mrud/5455016 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/Rscript | |
# Author: (c) Ulrich Dangel <uli@debian.org> | |
# License: BSD | |
library(getopt) | |
spec = matrix(c( | |
'help', 'h', 0, "logical", "Usage information", | |
'csv', 'i', 1, "character", "Input csv file", | |
'output', 'o', 1, "character", "output file (png)" | |
), ncol=5,byrow=TRUE) | |
opt = getopt(spec) | |
if ( !is.null(opt$help) ) { | |
cat(getopt(spec, usage=TRUE)); | |
q(status=1) | |
} | |
if ( is.null(opt$csv) ) { | |
write("csv file missing",stderr()); | |
cat(getopt(spec, usage=TRUE)); | |
q(status=1) | |
} | |
if ( is.null(opt$output) ) { | |
write("output file missing",stderr()); | |
cat(getopt(spec, usage=TRUE)); | |
q(status=1) | |
} | |
if (! file.exists(opt$csv) ){ | |
write("input file does not exist",stderr()); | |
cat(getopt(spec, usage=TRUE)); | |
q(status=1) | |
} | |
library("reshape") | |
votes <- read.csv(opt$csv) | |
votes2 <- melt(subset(votes, select=c("Year", "DDs", "unique")), id="Year") | |
library("ggplot2", quietly=TRUE, warn.conflicts=FALSE) | |
p <- ggplot(votes2, aes(Year, value, group=variable, fill=variable))+ ylab('DD #') | |
p <- p + geom_point() + geom_line() + geom_area(position='identity') | |
p <- p + scale_fill_manual("Values", values=c(alpha('#d70a53', 0.5), alpha("blue", 0.5)), | |
breaks=c("DDs", "unique"), labels=c("Developer count", "Voters")) | |
p <- p + opts(title="DPL votes") | |
png(opt$output, width=1024) | |
print(p) | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment