2013-02-19 80 views
4

我正在尝试将一个简单的图例添加到自定义对图。如何在R中使用与布局结合的对函数?

这里是reproductible代码(没有我的定制对功能):

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

为什么对功能“擦除”我的布局信息?

谢谢你的帮助。

+1

的“为什么”是很容易。因为'pair'本身就会调用'layout'。但是如果你想获得你想要的任何输出,你将不得不提供一个更完整的例子。 – joran 2013-02-19 02:36:08

+0

...在别人指责我之前我应该​​说我不确定'pairs'是否直接调用'layout',它可以简单地做'par(mfrow =)',但效果是一样的:它定义了它自己的布局。 – joran 2013-02-19 02:37:47

+2

它使用'par(mfrow =)' mnel 2013-02-19 02:39:15

回答

10

包含在帮助layout警告是

这些功能与其它机制的装置上布置绘图完全不相容:PAR(mfrow),参数(mfcol)

不幸的是,pairs使用mfrow来安排情节。

Duncan Murdoch and Uwe Ligges on R help使用的提示,你可以设置oma到一个合理的值给你的空间就在身边的传奇人物,如

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

enter image description here

+0

好的谢谢你。 因此,如果我想要并排绘制一对图形和一个图例,是否必须完全重写对函数并调用par(mfrow =)与我的布局兼容? – Chapo 2013-02-19 02:40:21

+0

@Chapo,看看[这个R-help线程](https://stat.ethz.ch/pipermail/r-help/2001-September/015379.html) – mnel 2013-02-19 02:50:59

+0

@Chapo,包括在我编辑的答案 – mnel 2013-02-19 02:57:21