Summary

It is worth restating the really important things about plotting:

  • Plots: plot(x,y) gives a scatterplot if x is continuous, and a box-and-whisker plot if x is a factor. Some people prefer the alternative syntax plot(y~x) using ‘tilde’ as in a model formula.
  • Type of plot: Options include lines type="l" or null (axes only) type="n".
  • Lines: lines(x,y) plots a smooth function of y against x using the x and y values provided. You might prefer lines(y~x).
  • Line types: Useful with multiple line plots, lty=2 (an option in plot or lines).
  • Points: points(x,y) adds another set of data points to a plot. You might prefer points(y~x).
  • Plotting characters for different data sets: pch=2 or pch="*" (an option in points or plot)
  • Setting non-default limits to the x or y axis scales uses xlim=c(0,25) and/or ylim=c(0,1) as an option in plot.

Get The R Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.