【问题标题】:Plot: Add legend that overlay several Frames绘图:添加覆盖多个框架的图例
【发布时间】:2015-06-09 18:30:25
【问题描述】:

我们如何编写一个覆盖多个帧的图例?

使用xpd参数,图例可以退出其帧,但仍不能进入下一帧。

par(mfrow=c(1,2))
plot(rnorm(120), rnorm(120))
legend(x = -0.1, y=0.1, legend = "Legend that covers both plots", text.col="red", cex=2, box.col="red", xpd=TRUE)
plot(rnorm(120), rnorm(120))

一个虚拟的解决方案是在每一帧上添加相同的图例,以便它们完美地互补。但这将是一个真正的痛苦。

【问题讨论】:

    标签: r graphics graph plot


    【解决方案1】:

    使用多行文字不是很好,但也许可以!

    op=par( mfrow = c( 1, 2 ), oma = c( 1.3, 0, 0, 0 ) )
    plot(rnorm(120), rnorm(120))
    plot(rnorm(120), rnorm(120))
    mtext("Legend that covers both plots", side=1, cex=1.5, col="red",outer = T,
           xpd=TRUE)
    mtext("Legend that covers both plots", line = -3,cex=1.5, col="red",outer = T)
    par(op)
    

    【讨论】:

      【解决方案2】:

      我经常在这些情况下使用layout

      op <- par(mar=c(3,3,1,1))
      layout(matrix(c(3,1,3,2),2,2), widths=c(4,4), height=c(1.5,4))
      layout.show(3)
      plot(rnorm(120), rnorm(120))
      plot(rnorm(120), rnorm(120))
      par(mar=c(0,3,1,1))
      plot(1, t="n", axes=FALSE, xlab="", ylab="")
      legend("center", legend = "Legend that covers both plots", text.col="red", cex=2, box.col="red", xpd=TRUE)
      par(op)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-26
        • 2020-08-06
        • 1970-01-01
        • 1970-01-01
        • 2016-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多