+3 votes
in Programming Languages by (71.8k 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 (353k points)
selected by
 
Best answer

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:

attach(mtcars)
par(mfrow=c(1,2))
plot(wt,mpg)
plot(wt,disp)
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

+5 votes
1 answer
+2 votes
1 answer
+3 votes
1 answer
+3 votes
1 answer

...