How to Format Numbers in R
How to Use Loops with Indices in R
How to Navigate RStudio

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

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.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
How to Add Points to a Plot in R
How to Install and Configure RStudio
How to Track Data Correlations in R
How to Do Basic Arithmetic in R
How to Work with Factors and Numeric Vectors in R Models and Calculations