factoextra icon indicating copy to clipboard operation
factoextra copied to clipboard

variable plot with ellipses grouped using colors

Open Olifair opened this issue 3 years ago • 3 comments

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

Olifair avatar Sep 08 '21 11:09 Olifair

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.

Nelson-Gon avatar Jan 17 '22 10:01 Nelson-Gon

@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.

Olifair avatar Jan 17 '22 11:01 Olifair

Bump, in case. Still having a similar issue

nweerasu avatar May 22 '24 16:05 nweerasu