Scatterplots in Base R

Here we introduce scatterplots in base R. The codes are simple, but you should also remember the options that make the plots more informative, like adding colors, legends, and error bars.

Scatter Plots

A scatter plot provides a graphical view of the relationship between two sets of numbers. Here we provide examples using the tree data frame from the trees91.csv data file. In particular, we look at the relationship between the stem biomass ("tree$STBM") and the leaf biomass ("tree$LFBM").

The command to plot each pair of points as an x-coordinate and a y-coordinate is "plot:"

> plot(tree$STBM,tree$LFBM)

It appears that there is a strong positive association between the biomass in a tree's stems and the tree's leaves. It appears to be a linear relationship. The correlation between these two sets of observations is quite high:

> cor(tree$STBM,tree$LFBM)
[1] 0.911595

Getting back to the plot, you should always annotate your graphs. The title and labels can be specified in exactly the same way as with the other plotting commands:

> plot(tree$STBM,tree$LFBM,
       main="Relationship Between Stem and Leaf Biomass",
       xlab="Stem Biomass",
       ylab="Leaf Biomass")

Source: K. Black, https://www.cyclismo.org/tutorial/R/plotting.html#scatter-plots
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 License.