Select Page

I love maps.  If done right, they can be compelling, beautiful, and informative; everything a good visualization should be.

Moreover, everyone understands them.  Granted, you still need a legend and a little explanation, but when someone looks at a map of the United States, they immediately “just get it” and know that they’re looking at the US.

(As an aside: this is a consequence of how our minds work.  Humans are “wired” to understand spatial data.  More on that topic another time.)

Here’s a visualization of unemployment data from 2008.  I created this in R using the GGPlot2 library.

This dataset has been visualized by several people, including Nathan Yao of Flowing data. I decided to re-create it myself using slightly different tools. Whereas Yao used standard ploting techniques, I used the GGPlot library to try to simplify things a little and to show how easy creating a map can be in R.

Keep in mind that I did need to do lots of “data shaping” to get the dataset into an appropriate format.

Still, setting that aside, this shows the power of using R to visualize your data.  Nine lines of code is all it takes to create a stunning choropleth map.

```ggplot() +
geom_polygon(data=map.states, aes(x=long,y=lat,group=group), fill=NA, color="#FFFFFF") +
geom_polygon(data=map.choropleth, aes(x=long,y=lat,group=group,fill=unemp_bin_pct), color="#EEEEEE")  +
scale_fill_brewer(palette ="YlOrRd") +
theme(panel.background = element_blank()) +
theme(axis.text = element_blank()) +
theme(axis.ticks = element_blank()) +
theme(axis.title = element_blank()) +
coord_map("polyconic")```