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

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

Here is the reproducible code (without my custom pair):

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

Why does a couple erase my layout information?

Thank you for your help.

+4
source share
1 answer

The warning contained in layout help is

These functions are completely incompatible with other mechanisms for organizing charts on the device: par (mfrow), par (mfcol)

Unfortunately, pairs uses mfrow to place charts.

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

 pairs(iris[1:4], main = "Anderson 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

+10
source

All Articles