O'Reilly logo

R Programming Fundamentals by Kaelen Medeiros

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required