How to Select Naming Styles in R
How to Define the Data Display Mode in R
How to Cast Data to Wide Format in R

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 Use Quantile Plots to Check Data Normality in R
How to Calculate Data Proportions and Find the Center in R
How to Work with Scales in a ggplot2 in R
How to Construct Vectors in R
How to Do Matrix Arithmetic in R