ggplot2: field manual

Author

Martin Frigaard

Welcome!

Welcome to the ggplot2 field manual!

I created this book as a sort of online ‘quick reference’ to help me answer questions like:1

  • What graph should I use?

  • What kind of graph is that?

  • Can (or should) I build that graph?

Getting started

  • Option 1: install ggplot2 using the code below:

    install.packages("ggplot2")
    library(ggplot2)

  • Option 2 (recommended): ggplot2 is also part of the tidyverse

    install.packages("tidyverse")
    library(tidyverse)

Who this book was written for

I created this resource with the following learner personas in mind:

  1. Garth is a data analyst putting together a slide deck for an upcoming meeting. He had a few statistics courses with R in college, and has picked up additional experience and skills from the different positions he’s held and various online tutorials. He’s currently building the graphs in his slides with ggplot2, but had grown tired of them and would like to customize his presentation to make it more engaging.

  2. Matilda is a data journalist hoping to add a few graphs to a piece she has been working on. She has 10 years of experience working with WordPress, writes and publishes on her own blog, and has an intermediate understanding of HTML & CSS. However, she has only been programming in R for about 6 months.

  3. Igor is a researcher who has been working in academia for 15 years. He’s comfortable writing R code, knows the kinds of graphs he’d like to build, but he only knows how to build these using the base R graphics. He’d like to learn how to duplicate the graphs he’s already created in base R using ggplot2.

Where to learn more

Because this is intended to be a field manual (and not a textbook), I’ve omitted most of the underlying principles and structure of the ggplot2 syntax.

If you’re looking for comprehensive resources on ggplot2, I recommend the excellent free text, the ggplot2 website, and Data Visualization: a practical guide by Kieran Healy.

If you know the graph you’d like to build, and you’re just looking for the code or package(s) to build it, I’d check out the R graph gallery or R graphics cookbook.

Another question to consider–but not covered in this manual–is, “who will the audience be for this graph?

Great resources for this include the Insightful Data Visualizations for “Uncreative” R Users course by Albert Rapp, Communicating with Data: The Art of Writing for Data Science by Deborah Nolan and Sara Stoudt, and the Truthful Art, The: Data, Charts, and Maps for Communication, by Alberto Cairo.


  1. Most of these questions come from #TidyTuesday↩︎