...

/

Introduction to Plotting

Introduction to Plotting

Learn to make excellent and professional quality figures from data.

Principles of effective figure making

Before we get into the details of how to plot our data most efficiently, it’s helpful to take a moment to talk about what makes a good figure. What is it that makes a high-quality figure, one that is suitable for publication or use in a presentation?

We would argue that judicious use of color, sizable clear text and labels, and efficient usage of plot space are three hallmarks of a good figure. Creating multiple panels to show different aspects of our data is often helpful. These fundamentals are the same whether we make our figures in R or not, and when we use either base graphics or ggplot2.

There are two main ways to make figures in R:

  1. We can use base graphics—that is, those built into the base version of R we downloaded from the Comprehensive R Archive Network (CRAN)—and the package ggplot2.
  2. There are functions in other packages (for example, the scatterplot() function in the car package or the barplot2() function in the gplots package), but they all utilize the basic coding of base graphics.

While ggplot2 and base graphics use different coding styles, the fundamentals that make a compelling graphic remain the same. Both types of coding allow us to build our graphics piece by piece and give us control over every aspect of the figure.

Let’s talk about some basics that are useful to know.

Defining colors

As with many things in R, there are multiple ways to define what colors to use. Each system has its pros and cons.

Numerical colors

If we’re making a simple plot to explore our data, the easiest way to define color is by using one of the nine basic numbered colors (for example, col=1). These are as follows: 0=white, 1=black, 2=red, 3=green, ...