VOOZH about

URL: https://www.geeksforgeeks.org/r-language/add-titles-to-a-graph-in-r-programming-title-function/

⇱ Add Titles to a Graph in R Programming - title() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Add Titles to a Graph in R Programming - title() Function

Last Updated : 15 Jul, 2025

In R Programming Language the title() function is often used to add annotations, titles, and labels to specific regions of a plot. The function allows customization of the main title, subtitle, and axis labels. Here's a brief explanation of the parameters commonly used with the title() function.

Syntax:

title(main = NULL, sub = NULL, xlab = NULL, ylab = NULL, …)

Parameters:

main: Main title of the graph

sub: Defines subtitles

Parameters used in the title function()

There are some common parameters that are used in title function.

  • xlab: Label for the X-axis.
  • ylab: Label for the Y-axis.
  • line: Line number where the title and subtitle start. Default is 3.
  • outer: If TRUE, titles are plotted in the outer margin.
  • col.main, col.sub, col.lab: Colors for the main title, subtitle, and axis labels.
  • cex.main, cex.sub, cex.lab: Character expansion for the main title, subtitle, and axis labels.
  • font.main, font.sub, font.lab: Font style for the main title, subtitle, and axis labels.

Adding title to the plot using title function()

Output:

👁 Image

In above example main title and sub titles are added to the plot. The arguments that can be used to change the font size are as follows:

  • cex.main: size for main title
  • cex.lab: text size for axis title
  • cex.sub: text size of the sub-title

Adding title to the plot using title function()

Output:

👁 Image

Adding title to the plot using title function()

Output:

👁 gh
Add Titles to a Graph in R Programming - title() Function
  1. Data Setup: Defines x and y as values for the x and y axes.
  2. Plot Creation: Uses the plot() function to create a colorful plot with specified axes and axis color.
  3. Title Customization: Calls title() to add a main title, subtitle, and customize fonts and colors for both titles and axis labels.
  4. Data Points: Adds red data points to the plot using points() for enhanced visualization.
  5. Legend Inclusion: Places a legend in the top-right corner to label the red data points with appropriate styling.
  6. Visualization: The final result is a visually appealing and customized plot with titles, labeled axes, data points, and a legend.


Comment
Article Tags:

Explore