title: Real-time auto incrementing ggplot in R
body: <p><a href="https://stackoverflow.com/questions/11365857/real-time-auto-updating-incremental-plot-in-r">This thread</a> answers how to create incremental plots in R with a real-time effect.</p>
  
  <p>I want to do the same thing with <code>ggplot2</code> instead of R's base <code>plot</code>. Directly copying from the answer in that link, I tried this but it didn't work:</p>
  
  <pre><code>n=1000
  df=data.frame(time=1:n,y=runif(n))
  window=100
  for(i in 1:(n-window)) {
    print(i)
    flush.console()
    ggplot(df) + geom_line(aes(x=time, y=y), size=0.7) + xlim(i,i+window)
    Sys.sleep(.09)
  }
  </code></pre>
  
  <p>I guess the image rendering for <code>ggplot2</code> works differently. Is it possible to create a real-time updating effect with <code>ggplot2</code>?</p>
  
  <p>Ideally, I want to be able to display multiple <code>geom_line</code>s. But I guess the logic will be the same.</p>
  
  <p>Also, is it possible to achieve this when the plot is "Zoom"ed in in R-Studio? </p>