title: xyplot, Error in `[.xts`(y, id) : 'i' or 'j' out of range
body: <p>I am trying to scatter plot two variables, one of which is the residuals from an <code>lm()</code> call. The <code>xyplot()</code> function will not do this scatter plot and returns the error message</p>
  
  <pre><code>Error in `[.xts`(y, id) : 'i' or 'j' out of range
  </code></pre>
  
  <p>The residuals are an xts variable and <code>xyplot()</code> can in fact still plot the residuals by itself (just a time plot, not a scatter plot). </p>
  
  <p>Strangely, the work around I've found so far is to use <code>as.xts()</code> on the already xts residuals, or to use <code>[ ,1]</code> indexing to refer to the first column, even though there is only one column to begin with.</p>
  
  <p>MWE is below, just looking for an explanation, thanks in advance.</p>
  
  <pre><code>library('lattice')
  library('xts')
  a = as.xts(ts(rnorm(20), start=c(1980,1), freq=4))
  b = as.xts(ts(rnorm(20), start=c(1980,1), freq=4))
  
  c = resid(lm(a~b))
  str(c) # xts object
  
  xyplot(c~a) # does not work: Error in `[.xts`(y, id) : 'i' or 'j' out of range
  xyplot(c) # xyplot can plot it by itself just fine
  xyplot(as.xts(c)~a) # works, if you use as.xts() on an xts object ?
  xyplot(c[ ,1]~a) # works, if you refer to the 1st column of a 1 column object ? 
  </code></pre>