标题重叠或外出

时间:2014-05-30 13:37:11

标签: r plot

我试图有4个情节,每个情节都有一个标题和一个主标题。 我首先尝试了这段代码:

set.seed(13);  
par(mfrow = c(2,2))  
for(i in 1:4){  
  plot(runif(10), t = "l", lwd = 3)  
  title(main='I have a title for each of the plots') 
}  
title(main="This is a very long title which needs to fit on two lines.\nUnfortunately it overlaps the other titles and it's not readible", outer=TRUE, line=-2)

enter image description here

我尝试让主标题更高或更低,但要么是超出屏幕,要么重叠其他标题。

拥有较大的情节不会有任何帮助...

有没有人知道如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

在此处发布@ rawr的答案以结束问题

set.seed(13);  
par(mfrow = c(2,2), oma = c(0,0,2,0))
for(i in 1:4){  
  plot(runif(10), t = "l", lwd = 3)  
  title(main='I have a title for each of the plots') 
}  
title(main=paste0("This is a very long title which needs to fit on two lines.\n",
     "Unfortunately it overlaps the other titles and it's not readable"), 
      outer=TRUE, line=-1)

诀窍是增加 o uter m 边距 a rea(oma=c(bottom, left, top, right))以增加顶部空间图像的空间有文字。并且还要将标题向上移动一点。

resulting image