title: Multiple Scatter plots with corresponding regression lines (& formula) using loops in R
body: <p>I know most of the programers would refer me to 'LATTICE' or 'ggplot2' packages of R as a solution to this question, but there must be a way to do it with the base package. I want to plot multiple graphs with corresponding regression lines and correlation coefficients with simple loops. An easy example data may look like-</p>
  
  <pre><code>a=list(cbind(c(1,2,3), c(4,8,12)), cbind(c(5,15,25), c(10,30,50)))
  par(mfrow=c(1,2))
  lapply(1:length(a), function(i)
    plot(a[[i]][,1], a[[i]][,2]))
  lapply(1:length(a), function(i)
    abline(lm(a[[i]][,2]~a[[i]][,1])))
  require(plotrix)
  lapply(1:length(a), function(i)
    boxed.labels(a[[i]][,1][1], a[[i]][,2][3], 
                 labels=paste(round(cor(a[[i]][,2], a[[i]][,1], use = "pairwise.complete.obs"),2)), 
                 border=FALSE, adj=0.5, cex=0.8))
  </code></pre>
  
  <p>If you run the above script you'd notice that all linear lines and r-values will plot on the top of the last graph. Is there any way to write in the call for regression along with the plot command? Or any other clever way to deal with loops to plot regressions on corresponding figures?? It works fine for a single plot (shown below), but I'm working with a considerably large list!</p>
  
  <pre><code>plot(a[[1]][,1], a[[1]][,2])
  abline(lm(a[[1]][,2]~a[[1]][,1]))
  boxed.labels(a[[1]][,1][1], a[[1]][,2][3],
               labels=paste(round(cor(a[[1]][,2], a[[1]][,1], use = "pairwise.complete.obs"),2)), 
                            border=FALSE, adj=0.5, cex=0.8)
  </code></pre>