Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outer margins in pairs() function

Tags:

plot

r

I have too much whitespace around the outside of my pairs() plot. How can one control the outer margins in a pairs() plot?

Changing oma for example does nothing (i.e. par(oma=c(0,0,0,0)) makes no difference).

like image 707
rhombidodecahedron Avatar asked Oct 23 '25 18:10

rhombidodecahedron


1 Answers

tl;dr use oma as an argument within your pairs() call.

As usual, it's all in the documentation, albeit somewhat obscurely. ?pairs states:

Also, graphical parameters can be given as can arguments to ‘plot’ such as ‘main’. ‘par("oma")’ will be set appropriately unless specified.

This means that pairs() tries to do some clever stuff internally to set the outer margins (based on whether a main title is requested); it will ignore external par("oma") settings, only paying attention to internal settings. The "offending" line within the code of stats:::pairs.default is:

  if (is.null(oma)) 
        oma <- c(4, 4, if (!is.null(main)) 6 else 4, 4)

Thus setting oma within the call does work:

par(bg="lightblue")  ## so we can see the plot region ...
z <- matrix(rnorm(300),ncol=3)
pairs(z,oma=c(0,0,0,0))

enter image description here

like image 129
Ben Bolker Avatar answered Oct 26 '25 08:10

Ben Bolker