title: Plotting a simple plane in 3D
body: <p>I am trying to plot a plane in a 3D environment in the context of a multivariate regression. I have a linear regression polynomial in the form of f(x)=beta_1 + beta_2*x_1 + beta_3 * x_3.</p>
  <p>Obviously this formula describes a plane in R^3. I would like to plot this, but I fail to see how to do this efficiently. Obviously, what I need to do is to create a sort of grid on which I compute the values of my regression polynomial.</p>
  <p>So far, this is what I have:</p>
  <pre><code>beta &lt;- c(1, 1, 1) #  Placeholder. This is the output of my regression analysis
  p &lt;- function(k) { t(beta) %*% k }
  
  n &lt;- 20
  m &lt;- 50
  
  x &lt;- seq(from=5, to=13, length.out=n)
  z &lt;- seq(from=20, to=50, length.out=m)
  M &lt;- mesh(x, z)
  </code></pre>
  <p>Now as far as I understand it, whether I'm using plot3D or rgl, I need to compute the value of <code>p</code> on these grid elements and store it in a matrix of dimension <code>m * n</code>. Obviously, in other languages I would just iterate over both matrices and fill the values in <code>y</code> by hand, but this seems very ugly and unfitting for R to me. So after some research, I stumbled upon the function <code>mapply</code>, which applies a function over two matrices. Note that the input to <code>p</code> requires a 1 to be appended to the argument before the call.</p>
  <pre><code>mapply(function (x1, x2) { p(c(1, x1, x2)) }, M$x, M$y)
  </code></pre>
  <p>But the output for this is very, very, very ugly and far from what I expected. Could someone help me out? It surprises me that plotting a plane in 3D seems to be so difficult, because after all, all that we need to uniquely determine a plane are three points in space. And yet all frameworks require me to use fairly complicated function calls?</p>
  <p>I am sorry if the solution to my issue is trivial. I've checked out quite a few similar threads, but I still can't quite wrap my head around what I need to do as the issue at hand should be so simple.</p>