library(readr) library(tidyverse) library(ggplot2) library(dplyr) library(tibble) library(tidyr) ## chargement fichiers cro <- read_delim("C:/Users/jarryl/Desktop/temp/croissants.csv", ";", escape_double = FALSE, trim_ws = TRUE) View(croissants) ##isole les q entre -27 et + 26 ° d'azimuth mosq1 <- filter(mosq, m_forme == "rectangle") ##mosq2 <- mosq1 %>% filter(m_azimuth < 26) summary(cro) View(cro) str(cro) ##Transformation de variables quantitatives en variables qualitatives test1 <- factor(mosq$maa_) summary(test1) str(test1) ##dispersion des variables 2 à 2 mosqs <- mosq[,-1] plot(mosqs[4:7], pch=21) ######################## ## Diagramme orientation ######################## cro1 <- filter(cro, cr_ouvert == "Taoudenni") cro1 <- cro %>% filter(cr_ouvert == "Taoudenni", na.rm = TRUE) ggplot(cro, aes(x = cr_azimut)) + geom_histogram(binwidth =5, fill = "wheat", color = "tomato4") + coord_polar(theta = "x", start = 3.15, direction = 1) + scale_x_continuous(limits=c(0,360),breaks=seq(-90, 90, 45))+ labs(title = "", x = "azimut", y = "nombre")+ facet_wrap(~cr_zone) ## par zone ## par zone et forme + facet_grid(m_zone~m_forme) ggplot(cro, aes(x = cr_azimut)) + geom_bar(width = 3, fill = "wheat", color = "tomato4") + coord_polar(theta = "x", start = 3.15, direction = 1)+ scale_x_continuous(limits=c(0,360),breaks=seq(-90, 90, 20))+ labs(x = "azimut", y = "nombre") ## par zone + facet_wrap(~cr_zone) ############### ## Histo ############### ggplot(cro) + geom_bar(aes(x = cr_zone), fill = "wheat", color = "tomato4") + labs(x = "zone", y = "nombre") # A l'intérieur des barres ggplot(data=mosq, aes(x=maa_zone, y=fid)) + geom_bar(stat="identity",fill = "wheat") theme_minimal() ## histo avec count ggplot(mosq) + aes(x = maa_anneau, fill = maa_anneau) + geom_bar(position = "fill") + geom_text(aes(label = ..count..), stat = "count", position = position_stack(.5)) + xlab("Forme") + ylab("Nombre")+ labs(fill = "Pratique du sport") + scale_y_continuous(labels = percent) ggplot(mosq) + aes(x = maa_zone, fill = maa_anneau) + geom_bar(position = "fill") + geom_text(aes(label = ..count..), stat = "count", position = position_fill(.5)) + xlab("CSP") + ylab("Proportion") + labs(fill = "Pratique du sport") + scale_y_continuous(labels = percent) ggplot(mosq) + aes(x = qualreg, fill = sport) + geom_bar(position = "fill") + stat_fill_labels() + xlab("CSP") + ylab("Proportion") + labs(fill = "Pratique du sport") + scale_y_continuous(labels = percent) ##barres horizontales ggplot(mosq) + geom_bar(aes((x = m_zone), fill = "wheat", color = "tomato4"), width=0.5) + labs(x = "zone", y = "nombre") + coord_flip() ggplot(mosq) + aes(x = m_forme, fill = m_forme) + geom_bar() + geom_text(aes(label = ..count..), stat = "count", position = position_stack(.5)) + xlab("") + ylab("Nombre") + labs(fill = "Forme") ggplot(mosq) + geom_histogram(aes(x = m_zone), fill = "wheat", color = "tomato4") ggplot(mosq) + geom_histogram(aes(x = m_qibla), fill = "wheat", color = "tomato4") ggplot(mosq) + aes(x = maa_azimuth) + geom_bar() + xlab("Nombre de frères et soeurs") + ylab("Effectifs") + facet_wrap(~maa_zone) + facet_grid(m_zone~m_forme) ##histo horizontal + coord_flip() ############### ## courbe ############### ##courbe de densité ggplot(mosq) + geom_density(aes(x = maa_azimuth, color= "tomato4"), bw = 5, fill = "wheat") + xlab("azimut") + ylab("fréquence") + labs(color = "Urbanité")+ facet_wrap(~maa_zone) ##courbe de densité par zone ggplot(mosq) + geom_density(aes(x = maa_azimuth, color = maa_zone), bw = 5) + xlab("azimut") + ylab("fréquence") + labs(color = "Zone") ################## ## violon, boxplot ################## ## pour m_area / m_zone ggplot(cro) + geom_boxplot(aes(x = cr_azimut, y = cr_zone), fill = "wheat", color = "tomato4", col = c("violetred", "steelblue1", "salmon1", "palegoldenrod", "olivedrab")) + scale_x_discrete("m_zone", limits = c("Piémont", "Aïr", "Tadarast", "Ighazer")) ggplot(mosq) + geom_violin(aes(x = m_qibla, y = m_orient), fill = "wheat", color = "tomato4") + scale_x_discrete("m_zone", limits = c("Piémont","Aïr", "Tadarast", "Ighazer")) ## pour m_azimuth / m_zone ggplot(mosq) + geom_boxplot(aes(x = m_zone, y = m_orient), fill = "wheat", color = "tomato4") + scale_x_discrete("m_zone", limits = c("Piémont", "Aïr", "Tadarast", "Ighazer")) ggplot(mosq) + geom_violin(aes(x = m_zone, y = m_orient), fill = "wheat", color = "tomato4") + scale_x_discrete("m_zone", limits = c("Piémont","Aïr", "Tadarast", "Ighazer")) ######## ## Point ######## ggplot(mosq) + geom_point(aes(x = m_qibla, y = m_larg, color = m_zone, size = m_orient )) ggplot(mosq) + geom_point(aes(x = m_qibla, y = m_larg), color = "tomato4", size = 3, alpha = 0.3) ggplot(mosq) + aes(x = m_qibla, y = m_larg, color = m_forme) + geom_smooth(method = "lm") + geom_point() + xlab("qibla (m)") + ylab("largeur (m)")+ labs(color = "Forme") ########## ## Mosaics ########## ## préparation table Zone/Forme tab <- as.matrix(table(mosq$m_zone, mosq$m_forme)) prop.table(tab) round(prop.table(tab)*100, 2) mosaicplot(tab, main = "Mosaïque des fréquences", xlab = "Zone", ylab = "Forme", las = 1, shade = TRUE) ## mZone/Annexe tab <- as.matrix(table(mosq$m_zone, mosq$m_annx)) round(prop.table(tab)*100, 2) mosaicplot(tab, main = "Mosaïque des fréquences", xlab = "Zone", ylab = "Annexe", las = 1, shade = TRUE) ## Zone/Toit tab <- as.matrix(table(mosq$m_zone, mosq$m_toit)) round(prop.table(tab)*100, 2) mosaicplot(tab, main = "Mosaïque des fréquences", xlab = "Zone", ylab = "Taille", las = 1, shade = TRUE) ## Zone/Pilier tab <- as.matrix(table(mosq$m_zone, mosq$m_pilier)) round(prop.table(tab)*100, 2) mosaicplot(tab, main = "Mosaïque des fréquences", xlab = "Zone", ylab = "Séparation des travées", las = 1, shade = TRUE) ## Zone/Urba tab <- as.matrix(table(mosq$m_zone, mosq$m_urba, mosq$m_forme)) round(prop.table(tab)*100, 2) mosaicplot(tab, main = "Mosaïque des fréquences", xlab = "Zone", ylab = "Urbanité", las = 1, shade = TRUE) ########## ## ACP ########## pca = prcomp(mosq[,4:7]) pca$rotation plot(pca) plot(pca$x[,1:2]) plot(pca$x[,1], rep(0,nrow(mosq))) biplot(pca) library(FactoMineR) #http://factominer.free.fr/factomethods/analyse-en-composantes-principales.html res.pca = PCA(mosq[,4:7], scale.unit=TRUE, ncp=5, graph=T) #scale.unit: pour choisir de réduire ou non les variables #ncp: le nombre de dimensions à garder dans les résultats #graph: pour choisir de faire apparaître les graphiques ou non res.pca = PCA(mosq, scale.unit=TRUE, ncp=5, quanti.sup=c(7:8), graph=T) plot.PCA(res.pca, axes=c(1, 2), choix="ind", habillage=3) dimdesc(res.pca, axes=c(1,2)) plotellipses(res.pca) ########## ## AFC ########## http://factominer.free.fr/factomethods/analyse-factorielle-des-correspondances.html res.ca.rows = CA(mosq[,4:7]) res.ca = CA(mosq, col.sup=13:16) res.mca = MCA(mosq, quanti.sup=16, quali.sup=c(9:14)) res = MFA(mosq, group=c(2,5,3,10,9,2), type=c("n",rep("s",5)), ncp=5, name.group=c("origin","odor","visual","odor.after.shaking", "taste","overall"), num.group.sup=c(1,6))