#install.packages(c("FactoMineR","tidyverse")) library(tidyverse) require(ggrepel) library(FactoMineR) # Données ---- db <- read.csv("https://epog.univ-paris13.fr/wp-content/uploads/2021/02/db4fevrier.txt", sep=",") #la ligne au dessus importe directement la base depuis le site d'epog #on prépare la base pour faire l'ACP pour_PCA<-db %>% mutate(poids=effectif/sum(effectif)) %>% select(-effectif,-ETABLI,-academie) %>% relocate(c("hommes","femmes","doctorats","masters","licences"),.after= prof_inter) # ACP ----- resultat_ACP<-PCA(pour_PCA[,1:17], quanti.sup=13:17, row.w=pour_PCA$poids) # FIG I : l'ébouli des pourcentages d'inertie (les valeurs propres) barplot(resultat_ACP$eig[,2],main="Part de chaque axe dans l'inertie totale", names.arg=1:nrow(resultat_ACP$eig),col=rainbow(15)) # FIG II : le cercle des variables -------------- plot.PCA(resultat_ACP,choix='var',title="Graphe des variables de l'ACP") #on peut faire la figure II à la main dbact<-as_tibble(resultat_ACP$var$coord) %>% mutate(type="Var actives") %>% mutate(names=c(rownames(resultat_ACP$var$coord))) dbsup<-as_tibble(resultat_ACP$quanti.sup$coord) %>% mutate(type="Var suppl") %>% mutate(names=c(rownames(resultat_ACP$quanti.sup$coord))) dbvar<-bind_rows(dbact,dbsup) ggplot(dbvar,aes(x=Dim.1,y=-Dim.2, label=names,color=type))+ scale_shape_manual(values=c("triangle","square"))+ geom_point(aes(shape=type))+ theme(legend.title=element_blank(), panel.background =element_rect(fill="white"), legend.position=c(0.15,0.85), legend.background = element_rect(fill="white",size=0.5, linetype="solid",colour ="black"), axis.title=element_text(size=12))+ geom_text_repel(size=4,show.legend = FALSE)+ geom_hline(yintercept=0,linetype="dashed",colour="grey")+ geom_vline(xintercept = 0,linetype="dashed",colour="grey")+ ggtitle("Figure II - Graphique des variables de l'ACP en 2019")+ xlab(paste("Axe 1 :",round(resultat_ACP$eig[1,2],0),"%"))+ ylab(paste("Axe 2 :",round(resultat_ACP$eig[2,2],0),"%")) #FIG III : individus -------------- plot.PCA(resultat_ACP,title="Graphe des individus de l'ACP") #la figure des individus à la main dbind<-bind_cols(db,as_tibble(resultat_ACP$ind$coord)) ggplot(data=dbind,aes(x=Dim.1,y=-Dim.2))+ ggtitle("Universités 2019 (couleur suivant Shanghaï)")+ scale_color_gradient(low = "green", high = "red")+ geom_point(aes(color=Classement))+ geom_text_repel(aes(color=Classement,label=Sigle),size=3)+ geom_hline(yintercept=0,linetype="dashed")+ geom_vline(xintercept = 0,linetype="dashed")+ theme(plot.title=element_text(hjust=0.5),legend.position=c(.95,.2), panel.background =element_rect(fill="white"),legend.title=element_blank())+ xlab(paste("Axe 1 :",round(resultat_ACP$eig[1,2],0),"%"))+ ylab(paste("Axe 2 :",round(resultat_ACP$eig[2,2],0),"%")) # Classification ----- resultat_classif <- HCPC(resultat_ACP, nb.clust=4) dbind<- dbind %>% mutate(groupe = resultat_classif$data.clust$clust) ggplot(data=dbind,aes(x=Dim.1,y=-Dim.2))+ ggtitle("Universités 2019")+ geom_point(aes(color=groupe))+ geom_text_repel(aes(color=groupe,label=Sigle),size=3)+ geom_hline(yintercept=0,linetype="dashed")+ geom_vline(xintercept = 0,linetype="dashed")+ theme(plot.title=element_text(hjust=0.5),legend.position=c(.95,.9), panel.background =element_rect(fill="white"),legend.title=element_blank())+ xlab(paste("Axe 1 :",round(resultat_ACP$eig[1,2],0),"%"))+ ylab(paste("Axe 2 :",round(resultat_ACP$eig[2,2],0),"%"))