Plot ellipse3d in R plotly?

梦想的初衷 提交于 2019-12-10 10:54:25

问题


Package rgl includes a very useful function ellipse3d, which can return an ellipsoid that cover like 95% percent of the points in 3D. Then this object can be used in rgl::plot3d to plot it out. My question is that is it possible to convert the output of ellipse3d to something that can be plotted through js plotting packages like plotly?

library(rgl)
dt <- cbind(x = rnorm(100), y = rnorm(100), z = rnorm(100))
ellipse <- ellipse3d(cov(dt))
plot3d(dt)
plot3d(ellipse, add = T, color = "red", alpha = 0.5)

Then what can I do to plot the ellipsoid through plotly?


回答1:


You can extract the coordinates of the ellipse from the ellipse$vb. Then plot these. Something like:

p <- plot_ly() %>% 
  add_trace(type = 'scatter3d', size = 1, 
     x = ellipse$vb[1,], y = ellipse$vb[2,], z = ellipse$vb[3,], 
     opacity=0.01) %>% 
  add_trace(data=dt, type = 'scatter3d', x=~x, y=~y, z=~z)



来源:https://stackoverflow.com/questions/42141505/plot-ellipse3d-in-r-plotly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!