title: ggplot2:scatterplots for all possible combinations of variables
body: <p>I want to plot graphs for all possible combinations of variables. My code is below:</p>
  
  <pre><code> set.seed(12345)
  a &lt;- data.frame(Glabel=LETTERS[1:7],   A=rnorm(7, mean = 0, sd = 1),  B=rnorm(7, mean = 0, sd = 1),  C=rnorm(7, mean = 0, sd = 1))
  T &lt;- data.frame(Tlabel=LETTERS[11:20], A=rnorm(10, mean = 0, sd = 1), B=rnorm(10, mean = 0, sd = 1), C=rnorm(10, mean = 0, sd = 1))
  
  library(ggplot2)
  for(i in 2:(ncol(a)-1))
  {
   for(j in (i+1):ncol(a))
   {
    r &lt;- 0.08
    p &lt;- ggplot(data=a, mapping=aes(x=a[, i], y=a[, j])) + geom_point() + theme_bw()
    p &lt;- p + geom_text(data=a, mapping=aes(x=a[, i], y=a[, j], label=Glabel),
                   size=3, vjust=1.35, colour="black")
    p &lt;- p + geom_segment(data = T, aes(xend = T[ ,i], yend=T[ ,j]),
                      x=0, y=0, colour="black",
                      arrow=arrow(angle=25, length=unit(0.25, "cm")))
    p &lt;- p + geom_text(data=T, aes(x=T[ ,i], y=T[ ,j], label=Tlabel), size=3, vjust=0, colour="red")
  dev.new()
    print(p)
  } 
   }
  </code></pre>
  
  <p>This code works fine. But the method used here is not recommended (<a href="https://stackoverflow.com/q/7452683/707145">See @baptiste comment</a>) and does not work in function. I want to know what is the best and recommended way to accomplish this task. Thanks in advance for your help.</p>