fviz_cluster() with an additional variable

85 views
Skip to first unread message

Gabriel Parriaux

unread,
May 28, 2024, 11:41:45 AM5/28/24
to FactoMineR users
I’m using fviz_cluster() to plot the distribution of my individuals according to two scores called "ml1" and "ml2" and to show the clusters they belong to.

I extract the data from a table called my_df1 that contains the score on the two axes and the information related to the clusters is retrieved from another table. The attribution of the individuals to the clusters has been done before with a kmeans clustering.

Here is the code I use to produce and display my plot:

fviz_cluster(list(data = my_df1,
                    cluster = as.factor(my_df2$cluster_label)),
                    palette = colors_6,
                    geom = "point",
                    ellipse = TRUE,
                    main = "Cluster mapping",
) +
  labs(title = "", y = ml2, x = ml1) +
  theme_minimal()

I would like to display on the same plot the information coming from another variable “degree” I have on my individuals, changing the shape of the point representing each individual, to see the possible relation between the clusters and the degree.

Unfortunately, I can’t find a way to do it… I saw some information about scale_shape_manual(), but I couldn't really use it properly.

Do you know if what I’m trying to do is possible and would you have a hint about how to do it?

Thank you,

Gabriel

francois.husson

unread,
May 28, 2024, 11:52:08 AM5/28/24
to factomin...@googlegroups.com
You should use thé package Factoshiny (ses my videos). Then you can perform the clustering, keep the clusters variable, and then perform a PCA with the cluster variable and the degree variable. You can draw the points thanks to 2 categorical variables with Factoshiny.

FH

-------- Message d'origine --------
De : Gabriel Parriaux <gabriel....@gmail.com>
Date : 28/05/2024 17:42 (GMT+01:00)
À : FactoMineR users <factomin...@googlegroups.com>
Objet : [SOCIAL]fviz_cluster() with an additional variable

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "FactoMineR users".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse factominer-use...@googlegroups.com.
Cette discussion peut être lue sur le Web à l'adresse https://groups.google.com/d/msgid/factominer-users/2b10b703-56ad-43de-b285-10ba203d185an%40googlegroups.com.

Gabriel Parriaux

unread,
Jun 3, 2024, 1:20:41 AM6/3/24
to FactoMineR users
Thanks a lot for your help about that!

I looked at some videos and tried to use Factoshiny, but unfortunately couldn’t get it with the visual interface. I got errors when I wanted to proceed to the clustering.

Finally, I found a way to do what I wanted directly with R code and ggplot, that worked pretty well. 

Thanks again for helping and all the best,

Gabriel

Reply all
Reply to author
Forward
0 new messages