Search code examples
rplotlyfactominer

using ggplotly on a factoextra object


Consider following code:

  library(FactoMineR)
  library(dplyr)
  library(factoextra)
  library(plotly)
  pca1<-PCA(iris[,1:4])
  fpi<-fviz_pca_ind(pca1,habillage = iris$Species)
  fpi
   

enter image description here

Now when execute following code, the groups repeat twice as shown in picture. How to solve this?

  ggplotly(fpi)

enter image description here


Solution

  • Just use label = "var"

    library(FactoMineR)
    library(dplyr)
    library(factoextra)
    library(plotly)
    pca1<-PCA(iris[,1:4])
    
    #Here use label = "var"
    fpi<-fviz_pca_ind(pca1,habillage = iris$Species, label = "var")
    fpi
    ggplotly(fpi)