【问题标题】:Positioning legend on plot divided by par(mfrow) in R在图上定位图例除以 R 中的 par(mfrow)
【发布时间】:2015-01-29 18:54:23
【问题描述】:

我使用

划分了我的绘图窗口
par(mfrow=c(2,4))

我有7个地块,想用剩余的地块空间来写图例(即右下角的空白处)

我想知道有没有一种简单的方法可以将图例放到这个位置?

pdf("Plot")
par(mfrow=c(2,4), lwd=2, font=2, font.lab=2, font.axis=2, oma=c(0,0,2,0))
for(i in 1:7){
    image(imagearray[,,i], axes=F, col=grey(c(0:225)/225), main= paste("Plot",i))
    title("Plot", outer=T)

}
dev.off()

【问题讨论】:

  • 请添加其余代码。

标签: r legend


【解决方案1】:

你没有说明你是如何生成图例的,所以我使用来自fields 包的image.plot。对于reprodicible example,我使用?image 中示例中的数据

您可以将title 和图例的位置移到循环之外。对于最终绘图,您可以使用frame() 前进到下一个绘图窗口,然后绘制图例。

# data
x <- 10*(1:nrow(volcano))
y <- 10*(1:ncol(volcano))

par(mfrow=c(2,4), lwd=2, font=2, font.lab=2, font.axis=2, oma=c(0,0,2,0))

for(i in 1:7){
  image(x, y, volcano, col = terrain.colors(100), 
                                 xlab="", ylab="", axes = FALSE)
}

title("Plot", outer=T)
frame()
fields::image.plot(x,y,volcano, 
                   legend.only = TRUE,
                   legend.width = 10,
                   legend.mar = 15, 
                   col = terrain.colors(100))

产生

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    • 2022-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多