Site icon R-bloggers

Choropleth tutorial and regression coefficient plots

[This article was first published on David B. Sparks » r, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

About two weeks ago, I gave short talk at Duke, wherein I presented a brief tutorial on creating choropleth maps in R using ggplot2. Since the code is already written, and the data and shapefiles already hosted online, I thought I would share the tutorial more widely.

A .ZIP file containing all the files necessary to follow the tutorial is available at: http://goo.gl/UrvQo.

The script goes very briefly through the loading of shapefiles and presidential election returns, and ends with the production of the choropleth below.

Click to enlarge

I don’t get into further customization of the map, as there are other more authoritative and complete sources for that. Further, much more detailed instruction on reading shape files are available from CSISS and NCEAS.

Included at the very end of the script is a brief example of a regression coefficient plot, something like a ggplot2 version of the coefplot() in Andrew Gelman‘s arm package.

I decided to develop the example into a function that takes as input a list() of model objects, and returns a ggplot2 object, which can be further modified by the user if so desired.

A coefficient plot comparing three models.

The script for the above plot can be found here. I also wrote a function that eschews arbitrarily discrete confidence bounds, instead attempting to suggest a sense of our confidence in the estimate without choosing a specific interval, since the difference between significance and insignificance is not itself significant. Code for the function is available here, and an example can be seen below.

Smoothed standard error coefficient plots


To leave a comment for the author, please follow the link and comment on their blog: David B. Sparks » r.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.