Titles and Axis Labels

If we want to add a title and custom axis labels to a base plot, it is simply a matter of adding extra inputs to plot(). If you examine the documentation for plot() using ?plot or help(plot), you'll see that plot can take a number of inputs that will do the following:

  • main, for plot titles
  • sub, for subtitles
    • These will be smaller than the title
    • Subtitles are printed at the bottom of the plot, beneath the x-axis label
  • xlab, to change the x-axis label
    • By default, the x-axis label will be the name of the variable you input as it is named in the dataset. Use xlab to change it.
  • ylab, to change the y-axis label
    • The y-axis defaults are the same as for the x-axis, and ylab works just as xlab does.

Let's return to ...

Get R Programming Fundamentals 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.