本文介绍了在R中绘制ellipse3d?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据包rgl包含一个非常有用的函数ellipse3d,该函数可以返回一个椭圆形,该椭圆形覆盖3D中95%的点.然后,可以在rgl::plot3d中使用此对象将其绘制出来.我的问题是,是否可以将ellipse3d的输出转换为可以通过诸如plotly的js绘图包进行绘图的内容?

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?

推荐答案

您可以从ellipse$vb中提取椭圆的坐标.然后绘制这些.像这样:

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)

这篇关于在R中绘制ellipse3d?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:48