Graphs


R Graphics Cookbook

My book about data visualization in R is available! The book covers many of the same topics as the Graphs and Data Manipulation sections of this website, but it goes into more depth and covers a broader range of techniques. You can preview it at Google Books.

Purchase it from Amazon, or direct from O'Reilly.


There are many ways of making graphs in R, each with its advantages and disadvantages. The focus here is on the ggplot2 package, which is based on the Grammar of Graphics (by Leland Wilkinson) to describe data graphics.

Graphs with ggplot2

  1. Bar and line graphs (ggplot2)
  2. Plotting means and error bars (ggplot2)
  3. Plotting distributions (ggplot2) - Histograms, density curves, boxplots
  4. Scatterplots (ggplot2)
  5. Titles (ggplot2)
  6. Axes (ggplot2) - Control axis text, labels, and grid lines.
  7. Legends (ggplot2)
  8. Lines (ggplot2) - Add lines to a graph.
  9. Facets (ggplot2) - Slice up data and graph the subsets together in a grid.
  10. Multiple graphs on one page (ggplot2)
  11. Colors (ggplot2)

Miscellaneous

  1. Output to a file - PDF, PNG, TIFF, SVG
  2. Shapes and line types - Set the shape of points and patterns used in lines.
  3. Fonts - Use different fonts in your graphs
  4. Antialiased bitmap output - If your plots look jagged or pixelated. (Not yet finished)

Basic graphs with standard graphics

  1. Histogram and density plot
  2. Scatterplot
  3. Box plot
  4. Q-Q plot

Other interesting graphs

  1. Correlation matrix