如何将对函数与R中的布局结合使用? [英] How to use the pairs function combined with layout in R?

查看:97
本文介绍了如何将对函数与R中的布局结合使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向自定义对图添加简单的图例.

I am trying to add a simple legend to a customized pairs graph.

这是可复制的代码(没有我的自定义配对功能):

Here is the reproductible code (without my customized pairs function) :

layout(cbind(1,2),width=c(1,1))
layout.show(2)
pairs(USJudgeRatings)

为什么pairs函数会擦除"我的布局信息?

Why is the pairs function "erasing" my layout information ?

推荐答案

layout帮助中包含的警告是

这些功能与在设备上布置绘图的其他机制完全不兼容:par(mfrow),par(mfcol)

These functions are totally incompatible with the other mechanisms for arranging plots on a device: par(mfrow), par(mfcol)

不幸的是,pairs使用mfrow来布置图.

Unfortunately, pairs uses mfrow for arranging the plots.

使用来自,您可以将oma设置为合理的值,以便为侧面留有图例,例如

Using the hints from Duncan Murdoch and Uwe Ligges on R help, you can set oma to a reasonable value to give you room for a legend on the side, eg

pairs(iris[1:4], main = "Anderson's Iris Data -- 3 species",
      pch = 21, bg = c("red", "green3", "blue")[iris$Species],
      oma=c(4,4,6,12))
# allow plotting of the legend outside the figure region 
# (ie within the space left by making the margins big)
par(xpd=TRUE)
legend(0.85, 0.7, as.vector(unique(iris$Species)),  
       fill=c("red", "green3", "blue"))

这篇关于如何将对函数与R中的布局结合使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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