+3 votes
in Programming Languages by (21.4k points)
I generated a plot containing 2 subplots. I can add titles to subplots using "main", but "main" is not adding a common title for the plot. Is there any function to add a common title to the plot?

1 Answer

+2 votes
by (51.1k points)
edited by

You can use the mtext() function of R to write a common title for the plot. This function writes text into one of the four margins of a plot.

You can choose the side of the text using the argument 'side' (1=bottom, 2=left, 3=top, 4=right).

Here is an example:

mtext("Common title (Scatterplot)", side = 3, line = -2, outer = TRUE)

 In this code, I am writing the plot's title on top (side=3). The code will use the outer margin (outer=TRUE) if available, and the title should be written on margin line -2 (line=-2).

The output of the above code is as follows:

Common plot title in R

Related questions