title: How to add a color key to a pairs() plot?
body: <p><strong>Goal:</strong> I have an adjusted <code>pairs</code> plot in <code>R</code> and I would like to add a color key to it. The panel backgrounds in the <code>pairs</code> plot show certain colors determined from a matrix of numbers. I would like to have a color key to the right of the <code>pairs</code> plot which shows these colors and some labels indicating the numbers.  </p>
  
  <p>I found some ways how to add color keys to <code>image()</code> plots (for example, <code>image.plot</code> in the <code>fields</code> package; <code>colorbar</code> in the <code>matlab</code> package; <code>color.legend</code> in the <code>plotrix</code> package). So, in principle, I would like to do something similar for my adjusted <code>pairs</code> plot. However, I already run into trouble with reserving some space for the color key to be plotted to (can [or even <em>should</em>?] this be done with <code>grid</code>?). </p>
  
  <p>Here is a minimal example of a <code>pairs</code> plot that has colored backgrounds. I also tried to adapt the example of <code>color.legend</code> in <code>plotrix</code> but this is more or less nonsense at the moment. Any ideas of how to do this in an elegant/flexible way? </p>
  
  <pre><code>count &lt;- 0
  color &lt;- c("yellow", "orange", "red", "lightgreen", "darkgreen", "cyan", "lightblue",
             "darkblue", "brown", "gray", "transparent", "transparent")
  mypanel &lt;- function(x, y, ...){
     count &lt;&lt;- count+1
     bg &lt;- color[count]
     ll &lt;- par("usr")
     rect(ll[1], ll[3], ll[2], ll[4], col=bg)
     points(x, y, cex=0.5)
  }
  
  U &lt;- matrix(runif(4*500), ncol=4)
  
  ## require(plotrix)
  ## par(mar=c(7,4,4,14)) # (bottom, left, top, right)
  pairs(U, panel=mypanel, gap=0)
  ## color.legend(xl=10.2, yb=2, xr=11, yt=5,
  ##              legend=c("bright","normal","dark"), rect.col=color, align="rb",
  ##              gradient="y")
  </code></pre>
  
  <p><strong>Info:</strong> The colors chosen above are determined from numbers (a vector of the same length). The numbers are all in between 0 and 1 and 0 (1) corresponds to the darkest (brightest) color. Those numbers should then determine the ticks and numbers printed at the color key (I don't need actual text labels -- I just tried that since the example of <code>color.legend</code> used it). So a vector of numbers for <code>colors</code> above could be <code>c(0.95, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 1, 1)</code> (the larger the number the brighter the column). To be more precise: These values are p-values determined by goodness-of-fit tests for each pair and the dark color should point out small p-values. Indeed, the colors are not that evenly spaced, I only use some colors above the significance level of (for example) 0.05, and most of the colors below 0.05, so one can directly see which tests lead to rejection.</p>