R-组合图的通用标题和图例

R-组合图的通用标题和图例,r,R,我想知道如何为R中的组合图提供一个通用标题和图例。我有四个组合成一个的图。每个情节都有自己的标题。我想在组合图的上中心指定一个公共标题,在左上角指定一个公共图例。我使用par()生成了组合图。我在下面提供了我的绘图您可以使用oma参数来增加外部边距, 然后用mtext添加主标题, 并尝试手动定位图例 op <- par( oma=c(0,0,3,0),# Room for the title and legend mfrow=c(2,2) ) for(i in 1:4) { p

我想知道如何为R中的组合图提供一个通用标题和图例。我有四个组合成一个的图。每个情节都有自己的标题。我想在组合图的上中心指定一个公共标题,在左上角指定一个公共图例。我使用par()生成了组合图。我在下面提供了我的绘图

您可以使用
oma
参数来增加外部边距, 然后用
mtext
添加主标题, 并尝试手动定位图例

op <- par(
  oma=c(0,0,3,0),# Room for the title and legend
  mfrow=c(2,2)
)
for(i in 1:4) {
  plot( cumsum(rnorm(100)), type="l", lwd=3,
  col=c("navy","orange")[ 1+i%%2 ], 
  las=1, ylab="Value",
  main=paste("Random data", i) )
}
par(op) # Leave the last plot
mtext("Main title", line=2, font=2, cex=1.2)
op <- par(usr=c(0,1,0,1), # Reset the coordinates
          xpd=NA)         # Allow plotting outside the plot region
legend(-.1,1.15, # Find suitable coordinates by trial and error
  c("one", "two"), lty=1, lwd=3, col=c("navy", "orange"), box.col=NA)

欢迎光临,文森特!在我学习R的早期阶段,你的网页对我非常有用。很好地说明了如何管理利润。我如何将“主标题”放在底部?