Reordered the loops in statplot.R