在图上定位图例除以R中的par(mfrow) [英] Positioning legend on plot divided by par(mfrow) in R

查看:116
本文介绍了在图上定位图例除以R中的par(mfrow)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的绘图窗口使用

par(mfrow=c(2,4))

我有7个图,并且想使用剩余的图空间来写图例(即,右下角的空白)

I have 7 plots and would like to use the remaining plot space to write the legend (i.e. the blank space in the bottom right hand corner)

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

I was wondering is there an easy way to put the legend into this position?

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()

推荐答案

您没有说明如何生成图例,因此我使用 reprodicible example ,我使用示例中的数据在?image

You dont indicate how you are generating the legend so i use image.plot from the fields package. For a reprodicible example i use the data from the examples in ?image

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

You can move title and the placement of the legend outside of the loop. For the final plot you can use frame() to move forward to the next plot window, and then plot the legend.

# 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))

产生

这篇关于在图上定位图例除以R中的par(mfrow)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆