'data.frame': 286 obs. of 43 variables:
$ Codes_essai_Labkey : Factor w/ 25 levels "B17VCE02004",..: 14 14 14 14 14 14 14 14 14 14 ...
$ Organisme : Factor w/ 18 levels "APVA","AXEREAL",..: 17 17 17 17 17 17 17 17 17 17 ...
$ lieu : Factor w/ 23 levels "AMIFONTAINE",..: 14 14 14 14 14 14 14 14 14 14 ...
$ Code_postal : Factor w/ 22 levels "10200","10210",..: 6 6 6 6 6 6 6 6 6 6 ...
$ Code_station_meteo : Factor w/ 18 levels "1001","1002",..: 5 5 5 5 5 5 5 5 5 5 ...
$ Commune_station_meteo: Factor w/ 18 levels "Angers","Boigneville",..: 6 6 6 6 6 6 6 6 6 6 ...
$ Type_de_sol : Factor w/ 16 levels "Argile","Argile_limono_sableuse",..: 13 13 13 13 13 13 13 13 13 13 ...
$ Precedent : Factor w/ 4 levels "Blé_dur","Blé_tendre_d'hiver",..: 1 1 1 1 1 1 1 1 1 1 ...
$ an : Factor w/ 2 levels "2017","2018": 1 1 1 1 1 1 1 1 1 1 ...
$ sem_t : chr NA NA NA NA ...
$ cond : chr NA NA NA NA ...
$ geno : Factor w/ 16 levels "AVIRON","BALLTRAP",..: 1 2 3 4 5 7 8 9 10 11 ...
$ psol_cm : num NA NA NA NA NA NA NA NA NA NA ...
$ ru_mm : num 150 150 150 150 150 150 150 150 150 150 ...
$ sem_j : chr "2016-11-21" "2016-11-21" "2016-11-21" "2016-11-21" ...
$ dens_sem_g_m2 : num NA NA NA NA NA NA NA NA NA NA ...
$ lev_j : chr "2016-12-12" "2016-12-12" "2016-12-12" "2016-12-14" ...
$ df_j : chr "2017-04-15" "2017-04-15" "2017-04-14" "2017-04-12" ...
$ drg_j : chr NA NA NA NA ...
$ ff_j : chr NA NA NA NA ...
$ mat_j : chr NA NA NA NA ...
$ rec_j : chr NA NA NA NA ...
$ surf_m2 : chr NA NA NA NA ...
$ h2o_pc : chr NA NA NA NA ...
$ rdt14_q_ha : num 66.5 66.8 69.2 58.1 67.7 ...
$ pb : chr NA NA NA NA ...
$ tp_pc : num 21.8 20.8 20.6 20 21.2 ...
$ pmg14_g : num 182 183 161 194 183 ...
$ np__m2 : num 60.7 60 59.7 52.7 59.7 ...
$ etfru_nb : chr NA NA NA NA ...
$ asc_j : chr NA NA NA NA ...
$ asc_pc : chr NA NA NA NA ...
$ ht_ff : chr NA NA NA NA ...
$ ht_rec : chr NA NA NA NA ...
$ Herbicides_1 : chr NA NA NA NA ...
$ Fongicides_1 : chr NA NA NA NA ...
$ Fongicides_2 : chr NA NA NA NA ...
$ Fongicides_3 : chr NA NA NA NA ...
$ Insecticides_1 : chr NA NA NA NA ...
$ Insecticides_2 : chr NA NA NA NA ...
$ Insecticides_3 : chr NA NA NA NA ...
$ Insecticides_4 : chr NA NA NA NA ...
$ Chlorose_ : chr NA NA NA NA ...
# Comptage des Valeurs_Manquantesna_counts <-colSums(is.na(bdd))na_percentage <- na_counts /nrow(bdd) *100# Création d'un bddframe des Valeurs_Manquantesna_df <-data.frame(Variable =names(na_counts), Valeurs_Manquantes = na_counts, Manquant = na_percentage)# Séparation des colonnes entierement vides et partiellement manquantesna_partial <- na_df %>%filter(`Manquant`>0&`Manquant`<100)na_full <- na_df %>%filter(`Manquant`==100)### 🔍 Affichage des colonnes partiellement manquantes # if(nrow(na_partial) > 0) {# cat("🔸 Colonnes avec des Valeurs_Manquantes partielles :\n")# kable(na_partial) %>%# kable_styling(bootstrap_options = c("striped", "hover"))# } else {# cat("✅ Aucune colonne partiellement manquante !")# }### 🔴 Affichage des colonnes avec 100% de Valeurs_Manquantes # if(nrow(na_full) > 0) {# cat("\n\n🚨 Colonnes avec 100% de Valeurs_Manquantes :\n")# kable(na_full) %>%# kable_styling(bootstrap_options = c("striped", "hover", "bordered"))# } else {# cat("\n✅ Aucune colonne entierement vide !")# }# 📊 Visualisation des Valeurs_Manquantes (colonnes partiellement manquantes)if(nrow(na_partial) >0) {cat("🔸 Colonnes avec des Valeurs_Manquantes partielles :")plot_missing(bdd %>% dplyr::select(any_of(na_partial$Variable)))}
🔸 Colonnes avec des Valeurs_Manquantes partielles :
Code
# 🔴 Visualisation des colonnes entierement videsif(nrow(na_full) >0) {cat("\n\n⚠️ Graphique des colonnes entierement vides :")plot_missing(bdd %>% dplyr::select(any_of(na_full$Variable)))}
⚠️ Graphique des colonnes entierement vides :
2.5 Descriptive statistics
Factors colums
Code
# Statistiques pour les variables numériquesdf <- bdd[, (colnames(bdd) %in%c(factor_colums))]df =droplevels(df)# Résumé des donnéessummary_df <-summary(df)# Convertir le résumé en data framesummary_df <-as.data.frame.matrix(summary_df)row.names(summary_df) =NULL# Créer une table bien formatée avec kableExtrakable(summary_df, format ="html") %>%kable_styling(bootstrap_options =c("striped", "hover", "condensed", "responsive"))
for (i in1:length(numeric_colums)) {cat ("For the colums : ", numeric_colums [i], "\n")print(summary(bdd[,numeric_colums [i]]))explo_num(nom_col = numeric_colums [i], titre = numeric_colums [i], df = bdd)}
For the colums : psol_cm
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
100 100 100 100 100 100 273
For the colums : ru_mm
Min. 1st Qu. Median Mean 3rd Qu. Max.
80.0 100.0 100.0 121.2 150.0 150.0
For the colums : dens_sem_g_m2
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
80.0 80.0 100.0 101.6 110.0 120.0 243
For the colums : rdt14_q_ha
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
27.54 41.77 48.83 50.25 59.53 78.28 5
For the colums : tp_pc
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
16.00 20.80 22.10 21.75 22.90 25.70 23
For the colums : pmg14_g
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
126.6 174.9 190.3 191.8 210.0 276.0 46
For the colums : np__m2
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
36.00 58.00 63.33 67.39 76.50 120.00 165
2.7 Boxplots pour les colonnes factorielles
Code
# Boucle sur toutes les colonnes catégoriellesfor (col in factor_colums) {cat("For the column:", col, "\n")# Création du graphique ggplot p <-ggplot(bdd, aes(x = .data[[col]])) +geom_bar(fill ="steelblue", color ="black", width =0.5) +# Largeur réduitelabs(x = col, y ="Nombre d'occurrences") +theme_minimal() +theme(axis.text.x =element_text(angle =45, hjust =1)) # Rotation des labelsprint(p) # Afficher le graphique}
For the column: Codes_essai_Labkey
For the column: Organisme
For the column: lieu
For the column: Code_postal
For the column: Code_station_meteo
For the column: Commune_station_meteo
For the column: Type_de_sol
For the column: Precedent
For the column: an
For the column: geno
2.8 Matrice de corrélation
Na missign values!
Code
df = bdd[,numeric_colums]cor_df <-round(cor(df,use='pairwise.complete.obs'), 2)#reshape2::melt the data framemelted_cor <- reshape2::melt(cor_df)#create correlation heatmapp =ggplot(data = melted_cor, aes(x = Var1, y = Var2, fill = value)) +geom_tile() +geom_text(aes(label =round(value, 2)), size =2) +scale_fill_gradient2(low ="blue", high ="red", mid ="white", midpoint =0, limit =c(-1, 1), name ="Correlation") +theme(axis.title.x =element_blank(),axis.title.y =element_blank(),panel.background =element_blank(),axis.text.x =element_text(angle =45, hjust =1, size =8),axis.text.y =element_text(size =8))# p <- ggplotly(p)p
Only 22 Code postal for 23 Lieu: Plaimpied Givaudins and CROSSES have the same Code postal \(=\) 18340
3.3 Interactive Map
Code
# bdd$Code_postaldf = bdd %>%filter(nchar(as.character(Code_postal)) <5)# View(df)df = bdd# df$Code_postaldf <- df %>%mutate(Code_postal =if_else(Code_postal =="2190", "02190", Code_postal))df <- df %>%mutate(Code_postal =if_else(Code_postal =="8300", "08300", Code_postal))df <- df %>%mutate(Code_postal = stringr::str_replace_all(Code_postal, " ", ""))df$Code_postal =as.character(df$Code_postal)# df$Code_postaldf$Code_postal =as.numeric(df$Code_postal)# Géocodage des lieubdd$lieu =as.character(bdd$lieu)geo_lieu <- bdd %>%distinct(lieu) %>%# Supprime les doublons tidygeocoder::geocode(address = lieu, method ="osm") # OpenStreetMap pour obtenir latitude & longitude# Fusionner avec les données originalesbdd_geo <- bdd %>% dplyr::left_join(geo_lieu, by ="lieu")bdd$lieu =as.factor(bdd$lieu)
Code
# Charger la carte de la Francefrance_map <-map_data("france")df_coord <- bdd_geo[, c("long", "lat")]df_coord$num_ligne <-seq(nrow(df_coord))carte <-leaflet(df_coord) %>%addTiles() %>%addCircleMarkers(lng =~long, lat =~lat, radius =0.8, fillOpacity =0.8, fillColor ="blue")carte
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
126.6 174.9 190.3 191.8 210.0 276.0 46
Code
hist(bdd[,"pmg14_g"])
Code
ggplot(bdd, aes(x =1, y = pmg14_g, color =as.factor(an))) +geom_jitter(width =0.2, size =2, alpha =0.7) +labs(title ="Average weight of a grain at 14% humidity by year",x ="",y ="PMG at 14%",color ="Years") +theme_minimal() +theme(axis.text.x =element_blank(), axis.ticks.x =element_blank())