title: Plotting Ellipse3d in R Plotly with surface ellipse
body: <p>Similar to the question here but this didn't give me excatly what I needed and I couldn't figure it out: <a href="https://stackoverflow.com/questions/42141505/plot-ellipse3d-in-r-plotly">Plot ellipse3d in R plotly?</a>. I want to recreate rgl's ellipse3d and surface ellipsoid in plotly. I know there there was an anwer which allowed plotting of an ellipse but as individual opaque markers, I need to get it as a surface ellipsoid that's slightly opaque so I can still see the data points in the ellipsoid.</p>
  
  <p>I tried to figure out how dww's comment for "add_surface" instead works but couldn't figure it out.... Can anyone help please?</p>
  
  <pre><code>if (!require("rgl")) install.packages("rgl")
  dt &lt;- cbind(x = rnorm(100), y = rnorm(100), z = rnorm(100))
  ellipse &lt;- ellipse3d(cov(dt))
  plot3d(dt)
  plot3d(ellipse, add = T, color = "red", alpha = 0.5)
  </code></pre>
  
  <p>dww's answer was:</p>
  
  <pre><code>if (!require("plotly")) install.packages("plotly")
  if (!require("rgl")) install.packages("rgl")
  dt &lt;- cbind(x = rnorm(100), y = rnorm(100), z = rnorm(100))
  ellipse &lt;- ellipse3d(cov(dt))
  
  p &lt;- plot_ly(mode = 'markers') %&gt;% 
    add_trace(type = 'scatter3d', size = 1, 
    x = ellipse$vb[1,], y = ellipse$vb[2,], z = ellipse$vb[3,], 
    opacity=0.01) %&gt;% 
    add_trace(type = 'scatter3d', x = dt[,1], y = dt[,2], z = dt[,3])
  p
  
  # shows more obviously what dww's code does to create the visual ellipsoid
  w &lt;- plot_ly(mode = 'markers') %&gt;% 
    add_trace(type = 'scatter3d',  
    x = ellipse$vb[1,], y = ellipse$vb[2,], z = ellipse$vb[3,], 
    opacity=0.5) %&gt;% 
    add_trace(type = 'scatter3d', x = dt[,1], y = dt[,2], z = dt[,3])
  w
  </code></pre>
  
  <p>Their comment on how to use add_surface was</p>
  
  <blockquote>
    <p>Note that for simplicity, I plotted the ellipse as a cloud using markers. If you want to use add_surface instead, you will have to first convert the ellipse into a different format, with a vector of x locations, a vector of y locations, z as a matrix (dimensions equal to x by y). You'll also need to split the z values into two separate surface layers one for the top half of the ellipsoid and one for the bottom. I don't have time right now to do all this, but if you get stuck I can work this out later</p>
  </blockquote>