kassambara / factoextra

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

New options in fviz_pca_biplot - use multiple grouping variables for different: aesthetics, color, shape, line #36

Open kassambara opened 7 years ago

kassambara commented 7 years ago

Hi,

I am trying to draw a biplot using FactoMineR and factoextra, with the function fviz_pca_biplot. I would like to know if it is possible to have two level to draw the plot:

I was able to define so far one by color, with that line: fviz_pca_biplot(res.pca, geom = "point", col.ind = as.numeric(DataPCA$region_Name)

But now, i would also add a line that would set shape point corresponding to another column of my data set.

Thank you for your help.

Regards,

lukkini commented 4 years ago

I am trying to do the same, if you you got it please tell me how. Thanks

dorian-groll commented 3 years ago

In case it can be useful to anyone, I have managed to do so with fviz_mca_ind using ggplot2 geom_point and accessing the desired variable to be grouped by shape through the return value following a MCA: among all the lists that are returned, the list "call" contains the original dataframe in "X". I don't see any reason why it would not work for a CA or a PCA: geom_point(aes(shape = res.pca$call$X$other_var_name)). Then, the label can also be changed as usual: labs(shape = "Desired label").

In the case of the original author's post:

fviz_pca_biplot(res.pca, 
                 geom = "point",
                 col.ind = as.numeric(DataPCA$region_Name)) +
     geom_point(aes(shape = res.pca$call$X$other_var_name)) +
     labs(shape = "Other label")
kmander7 commented 3 years ago

Based on the suggestion by @nairo-d I was able to change color and shape of the points...sort of. The geom_points are actually a layer over the biplot, rather than the color as a fill for the points. But it is an OK work around.

The bigger problem, however, is that the color variable is a factor that I would like to specify in the legend, instead of the default ("Col." with a numerical scale). I can change the legend name using labs(color = "Factor"), but the labels are still a numeric list rather than the factor level names. I tried to specify using scale_color_gradientn() but then it completely disappeared from the legend.

What I really want to do is easily color the points by one factor and use a second factor to specify the shape. Then have a legend that indicate what the colors and shapes correspond to. Is this possible?

roberthardt commented 1 year ago

I would also appreciate if one can assign shape and color to different categorical/factor columns. Thus having an argument like col.shape and ind.shape would be perfect.

Best

Robert

ivan-paleo commented 4 months ago

That would be a very nice feature indeed. Is there any plan on that? It seems the issue is open since 2017...