I have a compilation of 4 plots drawn together with par(mfrow=c(2,2))
. I would like to draw a common title for the 2 above plots and a common title for the 2 below panels that are centered between the 2 left and right plots.
Is this possible?
The mfrow() parameter allows to split the screen in several panels. Subsequent charts will be drawn in panels. You have to provide a vector of length 2 to mfrow() : number of rows and number of columns. Note: mfcol() does the same job but draws figure by columns instead of by row.
The par() function is used to set or query graphical parameters. We can divide the frame into the desired grid, add a margin to the plot or change the background color of the frame by using the par() function. We can use the par() function in R to create multiple plots at once.
title() function in R Language is used to add main title and axis title to a graph. This function can also be used to modify the existing titles. Syntax: title(main = NULL, sub = NULL, xlab = NULL, ylab = NULL, …)
This should work, but you'll need to play around with the line
argument to get it just right:
par(mfrow = c(2, 2)) plot(iris$Petal.Length, iris$Petal.Width) plot(iris$Sepal.Length, iris$Petal.Width) plot(iris$Sepal.Width, iris$Petal.Width) plot(iris$Sepal.Length, iris$Petal.Width) mtext("My 'Title' in a strange place", side = 3, line = -21, outer = TRUE)
mtext
stands for "margin text". side = 3
says to place it in the "top" margin. line = -21
says to offset the placement by 21 lines. outer = TRUE
says it's OK to use the outer-margin area.
To add another "title" at the top, you can add it using, say, mtext("My 'Title' in a strange place", side = 3, line = -2, outer = TRUE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With