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

后端 未结 4 1651
礼貌的吻别
礼貌的吻别 2020-12-23 13:44

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

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-23 13:49

    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)

提交回复
热议问题