title: R - How to get data from interpolated contour plot
body: <p>I'm using "R" for some time now. My actual problem is located in the area of 3d plots and interpolation.</p>
  
  <p>I have a data frame with 3d data. Let's say it's an area and the corresponding elevation. I only have a few points of interest and use the interpolation feature. The 3d plot gives me a heatmap and contour lines.</p>
  
  <p>Now I am interested in the contour line of a constant height, and I want to get the X and Y coordinates of it. For example the actual interpolation data does not contain all the points that are exactly zero.</p>
  
  <pre><code>test = data.frame(x = rep(c(1,2,3), 3), y = c(rep(1,3),rep(2,3),rep(3,3)), z = rnorm(9, 0, 1))
  mat = as.matrix(interp(test$x, test$y, test$z, nx = 10, ny = 10, duplicate = "strip"))[[3]]
  
  image(mat)
  contour(mat, add = TRUE)
  contour(mat, add = TRUE, levels = 0, lwd = 3)
  </code></pre>
  
  <p>I tried several fitting functions like lm, loess, lowess, nls and so on. But none of them works for me. Either it's for 2d data or it's giving me completely different data points than the contour lines.</p>
  
  <p>Any ideas?</p>
  
  <p>Best regards,</p>
  
  <p>Lalle</p>