From 9dd131fa497daf9f65e113534df20c48ee5f07df Mon Sep 17 00:00:00 2001 From: "louis.heraut" <louis.heraut@inrae.fr> Date: Tue, 18 Jan 2022 22:08:57 +0100 Subject: [PATCH] Matrix for date variable --- plotting/break.R | 2 +- plotting/layout.R | 10 ++--- plotting/map.R | 10 ++--- plotting/matrix.R | 94 +++++++++++++++++++++++++------------------- processing/analyse.R | 2 +- processing/extract.R | 66 +++++++++++++++---------------- processing/format.R | 2 +- script.R | 10 ++--- 8 files changed, 105 insertions(+), 91 deletions(-) diff --git a/plotting/break.R b/plotting/break.R index 7daa4bf..dd4de67 100644 --- a/plotting/break.R +++ b/plotting/break.R @@ -1,5 +1,5 @@ # \\\ -# Copyright 2021-2022 Louis Héraut*1 +# Copyright 2021-2022 Louis Héraut*1 # # *1 INRAE, France # louis.heraut@inrae.fr diff --git a/plotting/layout.R b/plotting/layout.R index b046c4f..80233e1 100644 --- a/plotting/layout.R +++ b/plotting/layout.R @@ -1,5 +1,5 @@ # \\\ -# Copyright 2021-2022 Louis Héraut*1 +# Copyright 2021-2022 Louis Héraut*1 # # *1 INRAE, France # louis.heraut@inrae.fr @@ -43,10 +43,10 @@ library(rgdal) library(shadowtext) # Sourcing R file -source('plotting/datasheet.R', encoding='latin1') -source('plotting/map.R', encoding='latin1') -source('plotting/matrix.R', encoding='latin1') -source('plotting/break.R', encoding='latin1') +source('plotting/datasheet.R', encoding='UTF-8') +source('plotting/map.R', encoding='UTF-8') +source('plotting/matrix.R', encoding='UTF-8') +source('plotting/break.R', encoding='UTF-8') ## 1. PERSONALISATION diff --git a/plotting/map.R b/plotting/map.R index 9e6eb74..dc17d75 100644 --- a/plotting/map.R +++ b/plotting/map.R @@ -1,5 +1,5 @@ # \\\ -# Copyright 2021-2022 Louis Héraut*1 +# Copyright 2021-2022 Louis Héraut*1 # # *1 INRAE, France # louis.heraut@inrae.fr @@ -540,7 +540,7 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer=1, outdirTmp='' # Up triangle text legend annotate('text', x=0.3, y=-20, - label=bquote(bold("Hausse significative à 10%")), + label=bquote(bold("Hausse significative à 10%")), hjust=0, vjust=0.5, size=3, color='grey40') @@ -552,7 +552,7 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer=1, outdirTmp='' # Circle text legend annotate('text', x=0.3, y=-29, - label=bquote(bold("Non significatif à 10%")), + label=bquote(bold("Non significatif à 10%")), hjust=0, vjust=0.7, size=3, color='grey40') @@ -564,7 +564,7 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer=1, outdirTmp='' # Down triangle text legend annotate('text', x=0.3, y=-40, - label=bquote(bold("Baisse significative à 10%")), + label=bquote(bold("Baisse significative à 10%")), hjust=0, vjust=0.5, size=3, color='grey40') @@ -652,7 +652,7 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer=1, outdirTmp='' # Text associated to the arrow annotate('text', x=2.8, y=valNorm*0.5, - label= "Plus sévère", + label= "Plus sévère", angle=90, hjust=0.5, vjust=1, size=3, color='grey50') diff --git a/plotting/matrix.R b/plotting/matrix.R index 4e940c4..4b7ef42 100644 --- a/plotting/matrix.R +++ b/plotting/matrix.R @@ -1,5 +1,5 @@ # \\\ -# Copyright 2021-2022 Louis Héraut*1 +# Copyright 2021-2022 Louis Héraut*1 # # *1 INRAE, France # louis.heraut@inrae.fr @@ -538,8 +538,8 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Position of a line to delimite periods x = Xc - 0.4 xend = X[length(X)] + 0.25 - y = height + 1 - yend = height + 1 + y = height + 1.1 + yend = height + 1.1 # Drawing of the line mat = mat + annotate("segment", @@ -552,7 +552,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice Start = trend_period[[j]][1] End = trend_period[[j]][2] # Name of the period - periodName = bquote(bold('Période')~bold(.(as.character(j)))) + periodName = bquote(bold('Période')~bold(.(as.character(j)))) # Naming the period mat = mat + annotate("text", x=x, y=yt, @@ -612,11 +612,11 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Writes a name for the period dates column mat = mat + - annotate('text', x=Xc, y=max(Y) + 0.85, - label=bquote(bold('Début')), + annotate('text', x=Xc, y=max(Y) + 0.9, + label=bquote(bold('Début')), hjust=0.5, vjust=0.5, size=3, color='grey20') + - annotate('text', x=Xc, y=max(Y) + 0.6, + annotate('text', x=Xc, y=max(Y) + 0.63, label=bquote(bold('Fin')), hjust=0.5, vjust=0.5, size=3, color='grey20') @@ -626,26 +626,26 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Extract the variable of the plot var = list_df2plot[[i]]$var mat = mat + - # Writes the type of the variable - annotate('text', x=X[i], y=max(Y) + 0.82, - label=bquote(.(var)), - hjust=0.5, vjust=0.5, - size=3.25, color='grey20') + # Writes the unit of the variable - annotate('text', x=X[i], y=max(Y) + 0.6, + annotate('text', x=X[i], y=max(Y) + 0.63, label=bquote('[%.'*ans^{-1}*']'), hjust=0.5, vjust=0.5, size=2, color='grey40') + - # Writes the type of the averaged variable - annotate('text', x=Xm[i], y=max(Y) + 0.82, - label=bquote('µ'*.(var)), + # Writes the type of the variable + annotate('text', x=X[i], y=max(Y) + 0.9, + label=bquote(.(var)), hjust=0.5, vjust=0.5, size=3.25, color='grey20') + # Writes the unit of the averaged variable - annotate('text', x=Xm[i], y=max(Y) + 0.6, + annotate('text', x=Xm[i], y=max(Y) + 0.63, label=bquote('['*m^3*'.'*s^{-1}*']'), hjust=0.5, vjust=0.5, - size=2, color='grey40') + size=2, color='grey40') + + # Writes the type of the averaged variable + annotate('text', x=Xm[i], y=max(Y) + 0.9, + label=expr(bar(!!var)), + hjust=0.5, vjust=0.5, + size=3.25, color='grey20') } # For all the station on the page @@ -718,8 +718,8 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Position of a line to delimite periods x = Xc_mean - 0.4 xend = Xm_mean[length(Xm_mean)] + 0.25 - y = height + 1 - yend = height + 1 + y = height + 1.1 + yend = height + 1.1 # Drawing of the line mat = mat + annotate("segment", @@ -732,7 +732,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice Start = mean_period[[j]][1] End = mean_period[[j]][2] # Name of the period - periodName = bquote(bold('Période')~bold(.(as.character(j+nPeriod_trend)))) + periodName = bquote(bold('Période')~bold(.(as.character(j+nPeriod_trend)))) # Naming the period mat = mat + annotate("text", x=x, y=yt, @@ -753,7 +753,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice y=y, yend=yend, color="grey40", size=0.35) # Naming the breaking columns - breakName = bquote(bold('Écart')~bold(.(as.character(j-1+nPeriod_trend)))*bold('-')*bold(.(as.character(j+nPeriod_trend)))) + breakName = bquote(bold('Écart')~bold(.(as.character(j-1+nPeriod_trend)))*bold('-')*bold(.(as.character(j+nPeriod_trend)))) # Writes the name mat = mat + annotate("text", x=x, y=yt, @@ -813,11 +813,11 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Writes a name for the period dates column mat = mat + - annotate('text', x=Xc_mean, y=max(Y) + 0.85, - label=bquote(bold('Début')), + annotate('text', x=Xc_mean, y=max(Y) + 0.9, + label=bquote(bold('Début')), hjust=0.5, vjust=0.5, size=3, color='grey20') + - annotate('text', x=Xc_mean, y=max(Y) + 0.6, + annotate('text', x=Xc_mean, y=max(Y) + 0.63, label=bquote(bold('Fin')), hjust=0.5, vjust=0.5, size=3, color='grey20') @@ -827,32 +827,46 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Extract the variable of the plot var = list_df2plot[[i]]$var mat = mat + - # Writes the type of the averaged variable - annotate('text', x=Xm_mean[i], y=max(Y) + 0.82, - label=bquote('µ'*.(var)), - hjust=0.5, vjust=0.5, - size=3.25, color='grey20') + # Writes the unit of the averaged variable - annotate('text', x=Xm_mean[i], y=max(Y) + 0.6, + annotate('text', x=Xm_mean[i], y=max(Y) + 0.63, label=bquote('['*m^3*'.'*s^{-1}*']'), hjust=0.5, vjust=0.5, - size=2, color='grey40') + size=2, color='grey40') + + # Writes the type of the averaged variable + annotate('text', x=Xm_mean[i], y=max(Y) + 0.9, + label=expr(bar(!!var)), + hjust=0.5, vjust=0.5, + size=3.25, color='grey20') + + library(ggtext) # If this is not the first period if (j > 1) { mat = mat + - # Writes the type of the breaking variable - annotate('text', x=Xr_mean[i], - y=max(Y) + 0.82, - label=bquote('d'*.(var)), - hjust=0.5, vjust=0.5, - size=3.25, color='grey20') + # Writes the unit of the breaking variable annotate('text', x=Xr_mean[i], - y=max(Y) + 0.6, + y=max(Y) + 0.63, label=bquote('[%]'), hjust=0.5, vjust=0.5, - size=2, color='grey40') + size=2, color='grey40') + + # Writes the type of the breaking variable + # annotate('text', x=Xr_mean[i], + # y=max(Y) + 0.9, + # label=expr(Delta*!!var), + # bquote('d'*.(var)), + # hjust=0.5, vjust=0.5, + # size=3.25, color='grey20') + + geom_richtext(aes(x=Xr_mean[i], + y=max(Y) + 0.9, + label="delta"), + hjust=0.5, vjust=0.5, + size=3.25, color='grey20', + fill=NA, label.color=NA, + label.padding= + grid::unit(rep(0, 4), + "pt")) + } } diff --git a/processing/analyse.R b/processing/analyse.R index 7ec789c..35fea94 100644 --- a/processing/analyse.R +++ b/processing/analyse.R @@ -1,5 +1,5 @@ # \\\ -# Copyright 2021-2022 Louis Héraut*1 +# Copyright 2021-2022 Louis Héraut*1 # # *1 INRAE, France # louis.heraut@inrae.fr diff --git a/processing/extract.R b/processing/extract.R index 1207e04..fc4f61f 100644 --- a/processing/extract.R +++ b/processing/extract.R @@ -1,5 +1,5 @@ # \\\ -# Copyright 2021-2022 Louis Héraut*1 +# Copyright 2021-2022 Louis Héraut*1 # # *1 INRAE, France # louis.heraut@inrae.fr @@ -46,76 +46,76 @@ iStatut = c('0'='inconnu', # Goal iFinalite = c('0'='inconnue', - '1'="hydrométrie générale", + '1'="hydrométrie générale", '2'='alerte de crue', - '3'="hydrométrie générale et alerte de crue", + '3'="hydrométrie générale et alerte de crue", '4'="gestion d'ouvrage", '5'='police des eaux', - '6'="suivi d'étiage", - '7'='bassin expérimental', + '6'="suivi d'étiage", + '7'='bassin expérimental', '8'='drainage') # Type of measure iType = c('0'='inconnu', - '1'='une échelle', - '2'='deux échelles, station mère', - '3'='deux échelles, station fille', - '4'='débits mesurés', + '1'='une échelle', + '2'='deux échelles, station mère', + '3'='deux échelles, station fille', + '4'='débits mesurés', '5'='virtuelle') # Influence of the flow iInfluence = c('0'='inconnue', '1'='nulle ou faible', - '2'='en étiage seulement', + '2'='en étiage seulement', '3'='forte en toute saison') # Type of flow -iDebit = c('0'='reconstitué', - '1'=paste("réel (prise en compte de l'eau rajoutée ", - "ou retirée du bassin selon aménagements)", +iDebit = c('0'='reconstitué', + '1'=paste("réel (prise en compte de l'eau rajoutée ", + "ou retirée du bassin selon aménagements)", sep=''), '2'='naturel') # Quality of low water flow -iQBE = c('0'='qualité basses eaux inconnue', - '1'='qualité basses eaux bonne', - '2'='qualité basses eaux douteuse') +iQBE = c('0'='qualité basses eaux inconnue', + '1'='qualité basses eaux bonne', + '2'='qualité basses eaux douteuse') # Quality of mean water flow -iQME = c('0'='qualité moyennes eaux inconnue', - '1'='qualité moyennes eaux bonne', - '2'='qualité moyennes eaux douteuse') +iQME = c('0'='qualité moyennes eaux inconnue', + '1'='qualité moyennes eaux bonne', + '2'='qualité moyennes eaux douteuse') # Quality of high water flow -iQHE = c('0'='qualité hautes eaux inconnue', - '1'='qualité hautes eaux bonne', - '2'='qualité hautes eaux douteuse') +iQHE = c('0'='qualité hautes eaux inconnue', + '1'='qualité hautes eaux bonne', + '2'='qualité hautes eaux douteuse') # Hydrological region iRegHydro = c('D'='Affluents du Rhin', - 'E'="Fleuves côtiers de l'Artois-Picardie", + 'E'="Fleuves côtiers de l'Artois-Picardie", 'A'='Rhin', 'B'='Meuse', 'F'='Seine aval (Marne incluse)', - 'G'='Fleuves côtiers haut normands', + 'G'='Fleuves côtiers haut normands', 'H'='Seine amont', - 'I'='Fleuves côtiers bas normands', + 'I'='Fleuves côtiers bas normands', 'J'='Bretagne', 'K'='Loire', 'L'='Loire', 'M'='Loire', - 'N'='Fleuves côtiers au sud de la Loire', + 'N'='Fleuves côtiers au sud de la Loire', 'O'='Garonne', 'P'='Dordogne', 'Q'='Adour', 'R'='Charente', - 'S'="Fleuves côtiers de l'Adour-Garonne", - 'U'='Saône', - 'V'='Rhône', - 'W'='Isère', + 'S'="Fleuves côtiers de l'Adour-Garonne", + 'U'='Saône', + 'V'='Rhône', + 'W'='Isère', 'X'='Durance', - 'Y'='Fleuves côtiers du Rhône-Méditérannée et Corse', - 'Z'='Îles', + 'Y'='Fleuves côtiers du Rhône-Méditérannée et Corse', + 'Z'='ÃŽles', '1'='Guadeloupe', '2'='Martinique', '5'='Guyane', @@ -123,7 +123,7 @@ iRegHydro = c('D'='Affluents du Rhin', '7'='Guyane', '8'='Guyane', '9'='Guyane', - '4'='Réunion') + '4'='Réunion') ## 2. SELECTION diff --git a/processing/format.R b/processing/format.R index 4fb3ab1..97cba2b 100644 --- a/processing/format.R +++ b/processing/format.R @@ -1,5 +1,5 @@ # \\\ -# Copyright 2021-2022 Louis Héraut*1 +# Copyright 2021-2022 Louis Héraut*1 # # *1 INRAE, France # louis.heraut@inrae.fr diff --git a/script.R b/script.R index 4ab6dd1..f67bfa4 100644 --- a/script.R +++ b/script.R @@ -1,5 +1,5 @@ # \\\ -# Copyright 2021-2022 Louis Héraut*1 +# Copyright 2021-2022 Louis Héraut*1 # # *1 INRAE, France # louis.heraut@inrae.fr @@ -133,10 +133,10 @@ rv_shpname = 'CoursEau_FXX.shp' setwd(computer_work_path) # Sourcing R file -source('processing/extract.R', encoding='latin1') -source('processing/format.R', encoding='latin1') -source('processing/analyse.R', encoding='latin1') -source('plotting/layout.R', encoding='latin1') +source('processing/extract.R', encoding='UTF-8') +source('processing/format.R', encoding='UTF-8') +source('processing/analyse.R', encoding='UTF-8') +source('plotting/layout.R', encoding='UTF-8') # Result directory resdir = file.path(computer_work_path, 'results') -- GitLab