library(FactoMineR) library(factoextra) library(ggplot2) datos<-read.csv("C:/Users/RV/Desktop/analisis de correspondencia/Datos_discretizados.xls") datos<-datos[,-1] names(datos)<-c("Empresa", "CIIU", "HHIN", "ID" , "C4" , "HN") categ <- apply(datos[,-1], 2, function(x) nlevels(as.factor(x))) modelo<-MCA(datos[,-1]) modelo$eig modelo$svd modelo$ind modelo$var fviz_contrib(modelo, choice ="var", axes = 1) fviz_contrib(modelo, choice ="var", axes = 2) #Nube de variables, y variables e individuos ------ fviz_mca_var(modelo, repel = TRUE) fviz_mca_biplot(modelo, repel = TRUE) + theme_minimal() #Opcional #Grafico incluyendo densidad(por numero de empresas)---- map_var<-data.frame(modelo$var$coord, Variable = rep(names(categ), categ)) map_indiv<-data.frame(modelo$ind$coord) ggplot(data = map_indiv, aes(x = Dim.1, y = Dim.2)) + geom_hline(yintercept = 0, colour = "gray70") + geom_vline(xintercept = 0, colour = "gray70") + geom_point(colour = "gray50", alpha = 0.7) + geom_density2d(colour = "gray80") + geom_text(data = map_var, aes(x = Dim.1, y = Dim.2, label = rownames(map_var), colour = Variable)) + ggtitle("MCA plot of variables using R package FactoMineR") + scale_colour_discrete(name = "Variable")