kassambara / factoextra

Extract and Visualize the Results of Multivariate Data Analyses
http://www.sthda.com/english/rpkgs/factoextra
355 stars 103 forks source link

variable plot with ellipses grouped using colors #139

Open Olifair opened 3 years ago

Olifair commented 3 years ago

Hello, I'm using ade4 and dudi.pca to do my analysis.

When I do a plot of individuals, with ellipses of my four groups, then this works fine : fviz_pca_ind(pc2, col.ind = datpca$group, # color by groups palette = c("blue", "red","lightblue","darkorange"), addEllipses = TRUE, # Concentration ellipses ellipse.type = "confidence", legend.title = "Groups", repel = TRUE )

where datpca is the dataframe used for the pca analysis (group variable is excluded), and the group is a factor with four levels.

However when I do : fviz_pca_var(pc2, col.var = datpca$group, # color by groups palette = c("blue", "red","lightblue","darkorange"), addEllipses = TRUE, # Concentration ellipses ellipse.type = "confidence", legend.title = "Groups", repel = TRUE )

I get the following error :

Error in fviz(X, element = "var", axes = axes, geom = geom.var, color = col.var, : The length of color variableshould be the same as the number of rows in the data.

The vector "datpca$group" is the same dataframe, so the length of the data is the same : there is no missing data in the data.frame. the PCA output "pc2" contains in $tab 12 observations, exactly as in the group vector. And anyway, it works for individuals. I have found similar questions on the web in different forums, but no answers.

I would be very happy if somebody could provide me with a way to work around this problem Thanks in advance for your time

Nelson-Gon commented 2 years ago

I am having a similar issue with fviz_pca_var, did you solve it? I think there's some bug in the internal working of length matching for fviz_pca_var. The .add_ind_groups function which is the source of this error does work fine independently.

Olifair commented 2 years ago

@Nelson-Gon No, sorry, I had to work around this problem. Haven't found a solution since neither. it seems that @kassambara is not active on this package anymore.

nweerasu commented 5 months ago

Bump, in case. Still having a similar issue