0

thanks for reading me. Im new with R so im lost on: how can i add group circles defined by a second factor on a biplot made with fviz_pca? I have this Table and want to apply a PCA to obtain a biplot where individuals are classified (colored) by the factor "UsoReg" (land use) (all good until here), but i also want to add circles (or some oval) to enclose (group) individuals by a second factor, named according to the column "Estacion" (season of the year), but i have no idea how to do that. So, How can I add circles to enclose (group) individuals by a second factor on a Biplot made with FactoMiner? (first factor is "UsoReg" and is colored through fill.ind function, second factor is "Estacion" and i dont know how to plot circles to group/enclose individuals according to their "Estacion" class). I want to visualize the 3 different seasons (Estacion:Otono, Invierno, Primavera) on the 3 different land use classes (CoigueIX, MixtaIX, AgricolaIX), please, thanks. Im using the following code:

PCA_PQ<-function(X){
pca.m<-prcomp(X, scale=TRUE)
contrib_rpca.m<-pca.m$rotation
c_pca.m<-pca.m$center
s_pca.m<-pca.m$scale}
scale(X,center=c_pca.m,scale=s_pca.m)
ev_pca.m<-get_eig(pca.m)
Biplot_pca.m<-fviz_pca_biplot(pca.m,
geom.ind="point",
fill.ind=IX_comp$UsoReg,
col.ind="cos2",
pointshape=21,pointsize=2,
mean.point=FALSE,
alpha.var="contrib",col.var="contrib",
gradient.cols=c("#00AFBB","#E7B800","#FC4E07"),
labelsize=5,
repel=TRUE,
xlab="PC 1",
ylab="PC 2")+
labs(fill="Uso", color="Contrib",alpha="Contrib")+
ggpubr::fill_palette(c("green","yellow","red"))+
theme(text=element_text(size=9),
axis.title=element_text(size=15),
axis.text=element_text(size=12))
plot(Biplot_pca.m)}

run

PCA_PQ(IX_comp[,c(4,6:14)]

return

Biplot1

Thanks!

1 Answers1

0

After looking and experimenting with different options i found that adding

ggplot2::stat_ellipse(aes(group=IX_comp$Estacion))

to the script above, i get what i was looking for biplot,

but now i need to change some parameters of the ovals printed in the plot, and add their labels to the legend.

I want to make ovals borders thinner, set different colors for them according to their factor classification (in IX_comp$Estacion) and add their names and colors to the legend.

Thanks for your help and attention!