How to Add Titles and Axis Labels to a Plot in R - dummies

How to Add Titles and Axis Labels to a Plot in R

By Andrie de Vries, Joris Meys

You can easily add the main title and axis labels with arguments to the plot() function in R to enhance the quality of your graphic.

  • main: Main plot title

  • xlab: x-axis label

  • ylab: y-axis label

To add a title and axis labels to your plot of faithful, try the following:


> plot(faithful,
+   main = "Eruptions of Old Faithful",
+   xlab = "Eruption time (min)",
+   ylab = "Waiting time to next eruption (min)")

R allows you to also take control of other elements of a plot, such as axes, legends, and text:

  • Axes: If you need to take full control of plot axes, use axis(). This function allows you to specify tickmark positions, labels, fonts, line types, and a variety of other options.

  • Legends: You can use the legend() function to add legends, or keys, to plots.

  • Text: In addition to legends, you can use the text() function to add text elements at any position on the plot.

The Help pages of the respective functions give you more information, and the examples contained in the Help pages show you how much you can do with these functions.