Week 3 Materials: ggplot2

This text from an RStudio tutorial will help you get an idea of what ggplot is all about:

ggplot2 has a rich underlying theory: the Grammar of Graphics, proposed by Leland Wilkinson. The grammer is based on of composition of building blocks according to certain rules. Statistical graphics are viewed as layers, each consisting of 4 elements:

  • Data
  • Mapping between variables and aesthetics (e.g. color, shape,scale)
  • Geometric Objects (e.g. points, lines, polygons)
  • Statistical Transformation (e.g. smoothing, binning in a histogram)

The user can explicitly specify these layers, and put them together according to the rules of the grammar. Layers can be saved or shared between plots, as they have a high-level representation in the code.

The lecture and exercises: rclub-ggplot2.r

Full ggplot documentation can be helpful.

As we’ve seen in a previous post, this package is pretty powerful for a variety of data viz needs (and desires).

3 comments

  1. rosem@uoregon.edu

    I just stumbled across a website for picking color schemes (http://colorbrewer2.org/), which is great for plotting. You can play around with different color options to see what works best for the structure of your data, and then export the number codes for those colors to use in R (or wherever). It even has a “colorblind safe” option you can check to only generate color schemes that colorblind members of your audience will still be able to see.

  2. Matt Stave

    The final figures in this blog post use the geom_density2d() function in the ggplot2 package in an interesting way. This plot makes it really easy to visualize multimodal distributions of density for a given vowel, like the /u/ in these Arapaho speakers’ data.

    I wasn’t aware when I first saw this, but the first four figures actually use the ‘vowels’ R package, written by Tyler Kendall, a sociolinguist here at the U of O.

    http://christiandicanio.blogspot.com/2013/10/visualizing-vowel-spaces-in-r-from.html