title: knitting rmarkdown throws error printing result of contour()
body: <p>I want to knit the following code into an html document. The code runs fine in Rstudio but fails when I attempt to knit - what am I missing here?</p>
  <pre><code>library(e1071)
  
  load(url(&quot;http://www.stanford.edu/~hastie/ElemStatLearn/datasets/ESL.mixture.rda&quot;))
  names(ESL.mixture)
  attach(ESL.mixture)
  
  plot(x,col=y+2,pch=c(17,19)[y+1],xlab=expression(x[1]),ylab=expression(x[2]),cex=1.5,cex.axis=1.5,cex.lab=1.5)
  
  data &lt;- data.frame(x, as.factor(y) )
  colnames(data) &lt;- c(&quot;x1&quot;, &quot;x2&quot;, &quot;y1&quot;)
  attach(data)
  
  svmfit &lt;- svm(y1 ~ x1 + x2, data = data, kernel = &quot;radial&quot;, cost = 32.1, gamma = 0.5, scale = FALSE)
  
  xgrid &lt;- expand.grid(x1=px1,x2= px2)
  ygrid &lt;- predict(svmfit,xgrid)
  
  plot(x,col=y+2,pch=c(17,19)[y+1],xlab=expression(x[1]),ylab=expression(x[2]),cex=1.5,cex.axis=1.5,cex.lab=1.5)
  
  points(xgrid,col=as.numeric(ygrid)+1,pch=20,cex=.2)
  contour(px1,px2,matrix(ygrid,69,99),level=1,add=TRUE)
  
  
  </code></pre>
  <p>This produced the following plot as desired.</p>
  <p><a href="https://i.stack.imgur.com/NoEkp.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NoEkp.jpg" alt="contour plot" /></a></p>
  <p>When attempting to knit it into a html report, it throws the following error. The dimensions of the data are definitely correct and those specified in the contour() call look fine as well, so am unclear on how to solve this.</p>
  <pre><code>Error in contour.default(px1, px2, matrix(ygrid, 69, 99), level = 1, add = TRUE) : 
    dimension mismatch
  Calls: &lt;Anonymous&gt; ... eval_with_user_handlers -&gt; eval -&gt; eval -&gt; contour -&gt; contour.default
  
  </code></pre>