Search code examples
rcluster-analysisgaussian

Visualizing 3D GMM


I want to know if there exists a way to visualize in 3D the clusters from Mclust. I know you can visualize in 2D the clusters, but I am curious about adding the 3rd dimension. How do you do that?

library(mclust
library(factoextra)
df<-data.frame(scale(iris[,-5]))
co<-Mclust(df, G=1:5)
fviz_mclust(co, "BIC", palette = "jco") # visualize optimal model and BIC values
fviz_mclust(co, "classification", geom = "point") # visualize clusters in 2D

Solution

  • I don't think fviz_mclust has 3D plot. However, you can use the following code instead to show the clusters in 3D with 3 features in iris:

    library(plot3D)
    scatter3D(df[,1],df[,2],df[,3], bty = "g", pch = 18, colvar =co$classification,
              col.var = co$classification, colkey =F,
              col = c("#1B9E77", "#D95F02"),
              pch = 18, ticktype = "detailed")