title: 3D plot of bivariate distribution using R or Matlab
body: <p>i would like to know if someone could tell me how you plot something similar to this
  <img src="https://i.stack.imgur.com/B4cuc.png" alt="enter image description here"> with histograms of the sample generates from the code below under the two curves. Using R or Matlab but preferably R.</p>
  
  <pre><code># bivariate normal with a gibbs sampler...
  
  gibbs&lt;-function (n, rho) 
  {
    mat &lt;- matrix(ncol = 2, nrow = n)
    x &lt;- 0
    y &lt;- 0
    mat[1, ] &lt;- c(x, y)
    for (i in 2:n) {
      x &lt;- rnorm(1, rho * y, (1 - rho^2))
      y &lt;- rnorm(1, rho * x,(1 - rho^2))
      mat[i, ] &lt;- c(x, y)
    }
    mat
  }
  
  
  
  bvn&lt;-gibbs(10000,0.98)
  par(mfrow=c(3,2))
  plot(bvn,col=1:10000,main="bivariate normal distribution",xlab="X",ylab="Y")
  plot(bvn,type="l",main="bivariate normal distribution",xlab="X",ylab="Y")
  
  hist(bvn[,1],40,main="bivariate normal distribution",xlab="X",ylab="")
  hist(bvn[,2],40,main="bivariate normal distribution",xlab="Y",ylab="")
  par(mfrow=c(1,1))`
  </code></pre>
  
  <p>Thanks in advance</p>
  
  <p>Best regards,</p>
  
  <p>JC T.</p>