Skip to main content

Resource Guide: R ggplot2

Last Updated: January 2024

ggplot2 is an R package for data visualization. It’s strengths include:

  • A common interface, set of functions, and parameters for all plot types
  • Exploring and visualizing your data by groups or categorical variables is easy
  • Many extension packages available for particular plot types

The resources listed here assume you have some basic familiarity with R.

Getting Started

R for Data Science (2nd edition)
Hadley Wickham, Mine Çetinkaya-Rundel, Garrett Grolemund
This book covers many data analysis topics, but it starts off with data visualization using the ggplot2 package. It does not assume you have R knowledge beyond knowing how to enter code into RStudio. It covers all of the basic components of making plots with ggplot2 and the features of the package that make working with data that contains groups or categorical variables easy.
Best for: a fairly quick but thorough tutorial.

Data Visualization in R with ggplot2
Kara Woo
If you prefer to learn from videos, this one-hour tutorial is available on O’Reilly Online (access available through Northwestern Libraries). The introductory sections may be a little slow, but the sections/videos where she writes code and shows how ggplot2 works move quickly; these start around the “Basic Plots” section.
Best for: those who prefer videos.

Data Visualization: A Practical Introduction
Kieran Healy
Written by a researcher, this book combines an introduction to effective data visualization principles with the ggplot2 code needed to implement them. The link is to an incomplete online draft of the book, but it contains much of the book’s content. All of the code is available in R Markdown documents in the socviz R package.
Best for: those who want to learn about good data visualization practices along with ggplot2.

Data Visualization Using R for Researchers Who Do Not Use R
Emily Nordmann, Phil McAleer, Lisa M. DeBruine
This book aims to introduce visualization using R specifically for researchers who have little to no prior experience in R with practical implementation. Using simulated data, the book walks you through some basics in R to help you import, summarize, and transform data and then provides examples to visualize the data using ggplot2. The book provides the dataset and interactive workbook to work through the tutorials.
Best for: researchers with little to no experience in R who would like a quick introduction to ggplot2 with interactive tutorial.

Getting Better

Tidy Tuesday
Tidy Tuesday is a weekly data visualization practice session. Each week, they pick a data set and encourage people to visualize it. People share their visualizations and code via Twitter. You can follow along to learn from others, but you’ll learn the most by challenging yourself to make a new plot each week, even if it’s simple.
Best for: motivation to practice your skills.

Fundamentals of Data Visualization
Claus O. Wilke
Also written by a researcher, this book focuses on teaching data visualization principles, not ggplot2. However, the book is written in R Markdown, and the graphics included in the book are made with ggplot2. All of the code to create the book is available in the GitHub repo.
Best for: those who want to make better visualizations and happen to use ggplot2 to do so.

ggplot2: Elegant Graphics for Data Analysis
Hadley Wickham
The other resources are primarily applied in nature: how to use ggplot2. This book is more towards the theory end of the application-theory spectrum. I would not start learning ggplot2 with this book, but it is a good option if you want to understand the “why” of ggplot2, not just the “how”. I got much better at using and solving problems with ggplot2 once I understood the grammar of graphics (the “gg” in “ggplot2”). Version 3 of the book is in-progress online and includes sections on extending ggplot2.
Best for: understanding the underlying theory and getting to know ggplot2 in depth.

Reference

Even regular users of ggplot2 don’t remember how to do everything. When using ggplot2, it’s common to need to look things up. When searching for answers online, include “ggplot” in your search, not just R. And remember that ggplot2 has evolved significantly over the past few years. Older answers may no longer be correct or show the best way to accomplish something with the current version of ggplot2.  When you don’t know what to search for or aren’t finding the answers you need, consider turning to a more systematic reference instead:

R Graphics Cookbook
Winston Chang
Like other cookbook style guides, this book has a clear table of contents and examples of how to perform many common data visualization tasks with ggplot2. For example, topics include how to: reverse an axis, remove grid lines, create your own color palette, make a heatmap, and change a legend title. Use it as a reference book — if you’re looking for a tutorial, try other resources listed here instead.

R Graph Gallery
While the large ads on this site can be distracting, it contains code examples to make hundreds of different plots in R. If you know what type of plot you want to make – either the name or what it looks like – but aren’t sure where to start, start here.