Good stuff for programming geeks
[ start | index | login or register ]
start > comment-start > 2004-11-02 > 1-1

Comment-start/2004-11-02/1-1 commented start/2004-11-02/1

Created by tmoertel. Last edited by tmoertel 1355 days ago. Viewed 608 times. #4
[diff] [history] [edit] [rdf]
labels
attachments
In case you're curious, here's the shell script and >>R code that I used to generate the above plot:

#!/bin/bash

# Generate all-states polling chart from electoral-vote.com data # Tom Moertel <tom@moertel.com> # 2004-11-02

# config

CSV=allpolls.csv FILEBASE=polls-by-state GS="gs -dSAFTER -dBATCH -dNOPAUSE"

# set up filenames

EPS=$FILEBASE.eps PNG=$FILEBASE.png PDF=$FILEBASE.pdf

# get polling data and add header to it

echo "Making sure we have polling data (delete $CSV to force download) ..."

[ -f $CSV ] || ( echo -n date,series,state,ev,kerry,bush,nader,released, echo unk2,unk3,unk4,unk5,unk6,unk7,unk8,source GET http://www.electoral-vote.com/info/$CSV ) > $CSV

# use R to generate plot in Postscript format # (uses X11 window so we can see the plot in passing)

echo Generating plots ...

R --no-save --no-init-file --no-restore-data <<EOF

polls <- read.csv("$CSV") require("lattice") trellis.device(x11, theme=col.whitebg()) p <- xyplot(kerry + bush ~ date | state, data=polls, main="Polling Numbers by State (Nov 2)", auto.key=list(rectangles=F,x=.75,y=.875,corner=c(1,1)), xlab="Elapsed days (1 = Sep 1)", ylab="Percentage who would vote for candidate") p dev.copy2eps(file="$EPS",family="Helvetica-Narrow")

EOF

# create other graphics formats

echo Rasterizing into PNG format ...

$GS -sDEVICE=pngalpha -dBackgroundColor='16#ffeebb' -dEPSCrop \ -sOutputFile=$PNG $EPS

echo Converting into PDF version ...

ps2pdf -dEPSCrop $SIZEPARMS $EPS

# done!

echo Done!

1 comment (by tmoertel) | post comment
community.moertel.com | Copyright © 2003–07 Moertel Consulting