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

后端 未结 4 1652
礼貌的吻别
礼貌的吻别 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:58

    You can use the function layout() and set two plotting regions which occurs in both columns (see the repeating numbers 1 and 3 in the matrix()). Then I used plot.new() and text() to set titles. You can play with margins and heights to get better representation.

    x<-1:10
    par(mar=c(2.5,2.5,1,1))
    layout(matrix(c(1,2,3,4,1,5,3,6),ncol=2),heights=c(1,3,1,3))
    plot.new()
    text(0.5,0.5,"First title",cex=2,font=2)
    plot(x)
    plot.new()
    text(0.5,0.5,"Second title",cex=2,font=2)
    hist(x)
    boxplot(x)
    barplot(x)
    

    enter image description here

提交回复
热议问题