title: R - ggplot2 contour plot
body: <p>I am trying to replicate the code from Andrew Ng's Machine Learning course on Coursera in R (as the course is in Octave).</p>
  
  <p>Basically I have to plot a non linear decision boundary (at p = 0.5) for a polynomial regularized logistic regression.</p>
  
  <p>I can easily replicate the plot with the base library:</p>
  
  <pre><code>contour(u, v, z, levels = 0)
  points(x = data$Test1, y = data$Test2)
  </code></pre>
  
  <p>where:</p>
  
  <pre><code>u &lt;- v &lt;- seq(-1, 1.5, length.out = 100)
  </code></pre>
  
  <p>and z is a matrix 100x100 with the values of z for every point of the grid.
  Dimension of data is 118x3.</p>
  
  <p>I cannot do it in ggplot2. Does somebody know how to replicate the same in ggplot2? I tried with:</p>
  
  <pre><code>z = as.vector(t(z))
  ggplot(data, aes(x = Test1, y = Test2) + geom_contour(aes(x = u, y = 
  v, z = z))
  </code></pre>
  
  <p>But I get the error: Aesthetics must be either length 1 or the same as the data (118): colour, x, y, shape</p>
  
  <p>Thanks.</p>
  
  <p>EDIT (Adding plot created from code of missuse):</p>
  
  <p><a href="https://i.stack.imgur.com/ZCfjT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZCfjT.png" alt="enter image description here"></a></p>