Open kassambara opened 7 years ago
I am trying to do the same, if you you got it please tell me how. Thanks
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")
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?
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
That would be a very nice feature indeed. Is there any plan on that? It seems the issue is open since 2017...
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,