5.1 Making a Basic Scatter Plot

5.1.1 Problem

You want to make a scatter plot using two continuous variables.

5.1.2 Solution

Use geom_point(), and map one variable to x and one variable to y.

We will use the heightweight data set. There are a number of columns in this data set, but we’ll only use two in this example (Figure 5.1):

A basic scatter plot

Figure 5.1: A basic scatter plot

5.1.3 Discussion

Instead of points, you can use different shapes for your scatter plot by using the shape aesthetic. A common alternative to the default solid circles (shape #19) is hollow ones (#21), as seen in Figure 5.2 (left):

The size of the points can be controlled with the size aesthetic. The default value of size is 2 (size = 2). The following code will set size = 1.5 to create smaller points (Figure 5.2, right):

Scatter plot with hollow circles (shape 21, left); With smaller points (right)Scatter plot with hollow circles (shape 21, left); With smaller points (right)

Figure 5.2: Scatter plot with hollow circles (shape 21, left); With smaller points (right)