Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common main title of a figure panel compiled with par(mfrow)

Tags:

graph

plot

r

title

par

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?

like image 392
ECII Avatar asked Feb 02 '13 09:02

ECII


People also ask

What is Mfrow?

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.

What is the par function in R?

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.

How do you make a title in R?

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, …)


1 Answers

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) 

enter image description here

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)

like image 54
A5C1D2H2I1M1N2O1R2T1 Avatar answered Oct 03 '22 06:10

A5C1D2H2I1M1N2O1R2T1