Purple America

Kevin Wayne - Princeton University

In this assignments, students create a Purple America map to visualize U.S. presidential elections. The map is a mashup of geographic and election return data, where each county is colored in a shade of red, green, and blue, according to the proportion of votes received by the Republican, Independent, and Democratic candidates. The results reveal that the U.S. is not as polarized as some political pundits would have us believe.

Purple America 2012
Students build several simple data types to model the geometric and election return data (e.g., polygons, counties, states, and elections), with no starter code. We provide the data in easily parsable text formats. By combining about 100 lines of good code with the prepared data, students produce striking visualizations of real data.


purple-america.html – Assignment handout
PurpleAmerica.pdf – Slides about this assignment (Kevin's Nifty SIGCSE talk)
purple-america-data.zip – Geographic and election return data files (5MB)


Summary Students write a program to visualize U.S. presidential election results.
Data visualization, graphics, parsing data files, object-oriented programming, associative arrays.
Students late in CS 1, after they know how to use graphics and how to parse data from a text file.
Students generate striking visualizations, using real data (and no starter code).
Real data can be messy, so we have pre-scrubbed the data (e.g., Kings County and the Borough of Brooklyn refer to the same geographic region in New York). Having students access in their original formats proved too cumbersome.
Works well with the graphics library from Introduction to Programming in Java but any graphics library that can draw filled polygons should suffice. The assignment is well suited to object orientation and associative arrays, but neither is required.
The assignment offers extensive opportunities for extensions, ranging from screen scraping to map projections to GUIs.