ggplot2: brief introduction

Nancy Reid
Feb 27

Reference: ggplot2, Elegant Graphics for Data Analysis

http://ggplot2.org

  • Chapter 2 surveys qplot; a quick way to convert from plot
  • Chapter 3 illustrates the grammar
  • Chapters 4 and 5 give details on layers, and on constructing common plots
  • Chapters 6 and 7 discuss fine control of scales, axes, legends, positioning
  • Chapter 8 polishing your plots for publication

Chapter 3 overview

Code available as mastery.r at http://ggplot2.org/book

library(ggplot2)
data(mpg)
head(mpg) # we'll use the fuel economony data set
  manufacturer model displ year cyl      trans drv cty hwy fl   class
1         audi    a4   1.8 1999   4   auto(l5)   f  18  29  p compact
2         audi    a4   1.8 1999   4 manual(m5)   f  21  29  p compact
3         audi    a4   2.0 2008   4 manual(m6)   f  20  31  p compact
4         audi    a4   2.0 2008   4   auto(av)   f  21  30  p compact
5         audi    a4   2.8 1999   6   auto(l5)   f  16  26  p compact
6         audi    a4   2.8 1999   6 manual(m5)   f  18  26  p compact

Help needed!