title: Plotting graphics under a loop operation in R
body: <p>The script below runs and plots the bayesian change point (bcp) of a data series with 6 columns of data referenced here as x &lt;-13:18 i.e. columns 13 through 18 in the data file 2GB01.csv. The problem is that only the output plot of column 18 is plotted. I need the script modified to plot the 6 graphs for each column data set in one graphic window partition.
  Any help?</p>
  
  <p>The data file looks something like this....
  col1 col2 ....col13 col14 col15 col16 col17 col18
  11    14       17    87    90    10     20    76
  23    87       87    16    09    17     87    65
  .     .        .     .     .     .      .     .
  .     .        .     .     .     .      .     .
  .     .        .     .     .     .      .     .</p>
  
  <p>The script is as written below....</p>
  
  <p>enter code here</p>
  
  <pre><code>  data2&lt;-read.csv("2GB01.csv", header=TRUE, row.names=1)
  
      x &lt;- 13:18
      for(i in seq(along=x)){
          ond&lt;-data2[,i]
          bcp.1&lt;-bcp(as.vector(ond))
      if (require("strucchange")) {
      bp &lt;- breakpoints(ond ~ 1, h = 2)$breakpoints
      rho &lt;- rep(0, length(ond))
      rho[bp] &lt;- 1
      b.num&lt;-1 + c(0,cumsum(rho[1:(length(rho)-1)]))
      bp.mean &lt;- unlist(lapply(split(ond,b.num),mean))
      bp.ri &lt;- rep(0,length(ond))
  
  
      for (i in 1:length(bp.ri)) bp.ri[i] &lt;- bp.mean[b.num[i]]
          xax&lt;-seq(1960, 2010, length=51)
          op &lt;- par(mfrow=c(2,1),col.lab="black",col.main="black")
          op2 &lt;- par(mar=c(0,4,4,4.5),xaxt="n",yaxt="n", cex.axis=0.75,las=2)
          plot(xax, ond, col="grey", pch=20, xlab="",ylab="", axes=T)
          lines(xax, bcp.1$posterior.mean, lwd=2)
          axis(4, yaxt="s")
          mtext('Posterior mean', las=0, side=4, line=3.5)
          lines(bp.ri, col="blue")
          par(op2)
          op3 &lt;- par(mar=c(5,4,0,4.5), xaxt="s",yaxt="n", cex.axis=0.75,las=2)
  plot(xax, bcp.1$posterior.prob, xlab="Year", ylab="Posterior   probability",     type="l", xlim=c(1960,2010), ylim=c(0,1),las=0)
      for (i in 1:length(bp.ri)) abline(v=xax[bp[i]], col="blue")
          axis(2, yaxt="s")
          par(op3)
          par(op)
  
  
  } else {
    cat("strucchange is not loaded")
  }}
  </code></pre>