简体   繁体   中英

How to use the pairs function combined with layout in 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)

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

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

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM