title: how to produce scatter plot matrix for two groups separately, but placing one in upper panel and the other in lower panel?
body: <p>I want to produce a scatter plot matrix for variables of two groups. But, how to place group 1 in the upper and group 2 in the lower panels with a different color for points? </p>
  
  <p>this is my dummy data:</p>
  
  <pre><code>structure(list(v = c(4.2, -0.8, 4.6, -0.8, 0.2, 0.2, 0.7, 2.1, 
  -2, -2.1, -2.9, -6.6, -2, -3.1, 0.2, 0.1, 5, 1.6, 0.7, -9.7, 
  -5.4, 1.7, -3.5, -4.6, -2.1, -0.9, 0.4, 0.9, -1.6, -2, -1.2, 
  -1.5, 0.7, 0.7, 3.9, 1.4, -0.8, -3.3, 3.2, 4, 2), u = c(1.7, 
  -0.9, -1.5, 4.3, -0.2, -0.5, 1.3, 3.4, 0.6, 0.6, 3.7, -2.7, -4.3, 
  -3.9, -5.9, -5.9, -4.8, -2.2, 1.2, -1.6, 6.8, 4.8, -0.9, -1.2, 
  -8, -8.3, 0.1, -1.6, -5.8, -6.4, 0.2, 10, 2.1, 2, 10.5, 3, 2.3, 
  2.2, -5.2, -6, -0.1), agl = c(250, 214.3, 53.6, 131, 563, 603, 
  693, 831, 129, 114, 2445, 514, 2556, 2112, 534, 474, 1263, 1228.9, 
  719, 460, 456, 303.2, 222, 76.1, 319.1, 605.2, 128.1, 131.8, 
  1503.2, 1557.1, 138.8, 691.1, 236, 224, 718, 279, 370, 1890, 
  3848, 4307, 381), WS = c(4.5, -0.8, 3.9, 0.1, 0.2, 0.2, 0.9, 
  3.5, 0.6, -1.7, -3.9, -5.7, -0.1, -1.5, 1.1, 1, 5.8, 0.4, 1, 
  -6.1, -1.7, 3.1, -3.6, -3, 6.4, 3.8, -0.4, 1.5, 5.7, 6, 1.2, 
  -3.5, 0.7, -0.7, 1.5, -2, 0.1, 2.4, 2.1, -1.9, -1.5), groups = c("two", 
  "one", "one", "one", "two", "two", "two", "two", "two", "two", 
  "two", "two", "two", "two", "two", "two", "two", "one", "two", 
  "two", "one", "one", "one", "one", "one", "one", "one", "one", 
  "one", "one", "one", "one", "two", "one", "two", "two", "two", 
  "two", "two", "two", "two")), row.names = c(NA, -41L), class = "data.frame")
  </code></pre>
  
  <p>I tried to do it this way without luck.</p>
  
  <pre><code>upper.panel&lt;-function(x, y){
      points(x,y, pch=19, cex=0.7)
      r &lt;- round(cor(x, y), digits=2)
      txt &lt;- paste0("R = ", r)
      usr &lt;- par("usr"); on.exit(par(usr))
      par(usr = c(0, 1, 0, 1))
      text(0.2, 0.9, txt)
  }
  
  pairs(df[ , 1:4], lower.panel = NULL, upper.panel = upper.panel)
  </code></pre>