【问题标题】:R - Common title and legend for combined plotsR - 组合图的通用标题和图例
【发布时间】:2012-02-02 22:48:54
【问题描述】:

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

【问题讨论】:

    标签: r


    【解决方案1】:

    可以使用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 的早期阶段,您的网页对我非常有用。很好地说明了利润管理。
    • 如何将“主标题”放在底部?
    猜你喜欢
    • 1970-01-01
    • 2022-09-24
    • 1970-01-01
    • 2021-11-17
    • 2020-12-07
    • 2018-02-09
    • 1970-01-01
    • 2019-08-01
    • 2021-01-02
    相关资源
    最近更新 更多