title: plot.window error in loop for R creating basic plots
body: <p>I apologize for not generating pseudo data for this question, but I think the problems I am facing are basic to most non novice individuals on this site. I am attempting to create a loop that plots a scatterplot of x and y for each value of a z variable.</p>
  
  <pre><code>x=rnorm(n=50)
  y=rnorm(n=50)
  z&lt;-rep(c(1,2,3,4,5),10)
  dataset &lt;-cbind(x,y,z)
  Dataset&lt;-as.data.frame(dataset)
  attach(Dataset)
  jpeg()
  z &lt;-Dataset$z[1:5]
  for(i in 1:5) {
      y&lt;-y[z==i]
      x &lt;-x[z==i]
      ARMAXpath&lt;-file.path("C:", "Desktop", paste("myplot_", z[i], ".jpg", sep="")) 
      jpeg(file = ARMAXpath)
      TheTitle = paste("Scatter Plots", z[i])
      plot.new()
      plot.window(xlim=c(0,1), ylim=c(5,10))
      plot(y,x)
      dev.off()
  }
  detach(Dataset)
  </code></pre>
  
  <p>No matter what I do I get the same <code>plot.window</code> error. I ran this code with and without attach. I ran it with and without <code>plot.window</code>. I also moved it in and outside the loop.</p>
  
  <pre><code>Error in plot.window(...) : need finite 'xlim' values
  In addition: Warning messages:
  1: In min(x) : no non-missing arguments to min; returning Inf
  2: In max(x) : no non-missing arguments to max; returning -Inf
  3: In min(x) : no non-missing arguments to min; returning Inf
  4: In max(x) : no non-missing arguments to max; returning -Inf
  </code></pre>
  
  <p>My question is how do I generate plots of two time series by a third variable in my dataset (i.e. region) write the output to a file folder as I have poorly attempted to do above?</p>