title: Using ggplot, how can I add a point at a time in a loop and then connect them all by a line after the loop?
body: <p>I am going dealing with a lot of data and I was thinking of plotting one part of the data at a time using a loop.</p>
  
  <p>Here's a sample of the data:</p>
  
  <pre><code>Department  Period  Sales
  1005    1   3354.256
  1005    1   5587.164
  1005    2   3946.055
  1005    2   5739.555
  1005    3   3990.139
  1005    3   6208.411
  1005    4   3887.84
  1005    4   6397.811
  1008    1   4014.629
  1008    1   5370.781
  1008    2   4311.249
  1008    2   5403.442
  1008    3   4028.125
  1008    3   6660.305
  1008    4   4564.816
  </code></pre>
  
  <p>My initial idea was to plot one point at a time and then connect the points with a line after exiting the loop.</p>
  
  <pre><code>gp &lt;- ggplot()
  
  for (i in 1:4) {
    dat &lt;- qdat[qdat$Period == i,]
    gp &lt;- gp + stat_summary(data = dat , aes(x=Period , y=Sales), geom="point", fun.y="sum")
    print(gp)
  }
  
  final_plot &lt;- gp + geom_line()
  </code></pre>
  
  <p>However, I only get the points, but am not able to generate any lines connecting the points.</p>
  
  <p>Ideally, I would also like to know if it's possible to plot different line segments at a time to make one continuous line using a loop.</p>
  
  <p>Thanks a lot!!</p>