我在此处使用包“rgl”遵循了有关 3D 可视化的教程
所以我能够用“虹膜”数据绘制一个 3D 散点图,并创建一个围绕 95% 数据点的椭球:
library("rgl")
data(iris)
x <- sep.l <- iris$Sepal.Length
y <- pet.l <- iris$Petal.Length
z <- sep.w <- iris$Sepal.Width
plot3d(x, y, z, col="blue", box = FALSE,
type ="s", radius = 0.15)
ellips <- ellipse3d(cov(cbind(x,y,z)),
centre=c(mean(x), mean(y), mean(z)), level = 0.95)
plot3d(ellips, col = "blue", alpha = 0.2, add = TRUE, box = FALSE)
Run Code Online (Sandbox Code Playgroud)
我知道前 50 个数据点与数据集的其余部分相比属于不同的群体,因此以不同的方式为它们着色,并用两个椭球覆盖它们:
plot3d(x, y, z, col=c(rep("gold2",50),rep("forestgreen",100)), box = FALSE,
type ="s", radius = 0.15)
ellips1 <- ellipse3d(cov(cbind(x[1:50],y[1:50],z[1:50])),
centre=c(mean(x[1:50]), …Run Code Online (Sandbox Code Playgroud)