How to use the pairs function combined with layout in R?

layout, r

Solution

A warning contained in the help for `layout` is

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

Unfortunately, `pairs` uses `mfrow` for arranging the plots.

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

Problem

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) ``` Why is the pairs function "erasing" my layout information ?

Original source