Commit d3fdf377 authored by Heraut Louis's avatar Heraut Louis
Browse files

Layout

parent c9d77420
No related merge requests found
Showing with 545 additions and 508 deletions
+545 -508
...@@ -407,562 +407,595 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice ...@@ -407,562 +407,595 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice
slice = nCode slice = nCode
} }
# Gets all the different type of plots
Type = levels(factor(Type_trend)) #### Type = levels(factor(Type_trend))
nbType = length(Type)
# For all the type of plots
# Extracts each possibilities of first letter of station code for (itype in 1:nbType) {
firstLetter = levels(factor(substr(Code, 1, 1))) # Gets the type
# Number of different first letters type = Type[itype]
nfL = length(firstLetter)
# For all the available first letter # Extracts each possibilities of first letter of station code
for (ifL in 1:nfL) { firstLetter = levels(factor(substr(Code, 1, 1)))
# Gets the first letter # Number of different first letters
fL = firstLetter[ifL] nfL = length(firstLetter)
# Print the matrix name # For all the available first letter
print(paste('Matrix for region : ', fL, for (ifL in 1:nfL) {
" (", round(ifL/nfL*100, 1), " %)", # Gets the first letter
sep='')) fL = firstLetter[ifL]
# Get only station code with the same first letter # Get only station code with the same first letter
subCodefL = Code[substr(Code, 1, 1) == fL] subCodefL = Code[substr(Code, 1, 1) == fL]
# Counts the number of station in it # Counts the number of station in it
nsubCodefL = length(subCodefL) nsubCodefL = length(subCodefL)
# Computes the number of pages needed to plot all stations # Computes the number of pages needed to plot all stations
nMat = as.integer(nsubCodefL/slice) + 1 nMat = as.integer(nsubCodefL/slice) + 1
# For all the pages # For all the pages
for (imat in 1:nMat) { for (iMat in 1:nMat) {
# Extracts the station for the current page # Print the matrix name
subCode = subCodefL[(slice*(imat-1)+1):(slice*imat)] print(paste('Matrix ', iMat, '/', nMat,
# Removes NA stations ' of ', type,
subCode = subCode[!is.na(subCode)] ' for region : ', fL,
# Reverses verticale order of stations " (",
subCode = rev(subCode) round((ifL + nfL*(itype-1)) / (nfL*2) * 100,
# Gets the number of station for the page 1),
nsubCode = length(subCode) " %)",
sep=''))
# Creates logical vector to select only info about
# stations that will be plot on the page
CodefL_trend = Code_trend %in% subCode
# Extracts those info
subPeriods_trend = Periods_trend[CodefL_trend]
subNPeriod_trend = NPeriod_trend[CodefL_trend]
subVar_trend = Var_trend[CodefL_trend]
subType_trend = Type_trend[CodefL_trend]
subCode_trend = Code_trend[CodefL_trend]
subPthresold_trend = Pthresold_trend[CodefL_trend]
subTrendMean_trend = TrendMean_trend[CodefL_trend]
subDataMean_trend = DataMean_trend[CodefL_trend]
subFill_trend = Fill_trend[CodefL_trend]
subColor_trend = Color_trend[CodefL_trend]
# Same for breaking analysis
CodefL_mean = Code_mean %in% subCode
# Extracts right info
subPeriods_mean = Periods_mean[CodefL_mean]
subNPeriod_mean = NPeriod_mean[CodefL_mean]
subVar_mean = Var_mean[CodefL_mean]
subType_mean = Type_mean[CodefL_mean]
subCode_mean = Code_mean[CodefL_mean]
subDataMean_mean = DataMean_mean[CodefL_mean]
subBreakMean_mean = BreakMean_mean[CodefL_mean]
subFill_mean = Fill_mean[CodefL_mean]
subColor_mean = Color_mean[CodefL_mean]
# Extracts the name of the currently hydrological
# region plotted
title = df_meta[df_meta$code == subCode[1],]$region_hydro
### Plot ###
# Fixes the height and width of the table according to
# the number of station and the number of column to draw
height = nsubCode
width = nbp * 2 * nPeriod_trend + nPeriod_trend + nPeriod_mean * nbp + nPeriod_mean + nbp
# Fixes the size of the plot area to keep proportion right
options(repr.plot.width=width, repr.plot.height=height)
# Open a new plot with a personalise theme
mat = ggplot() + theme_ash +
# Modification of theme in order to remove axis
theme(
panel.border=element_blank(),
axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank(),
plot.margin=margin(t=5, r=5, b=5, l=5, unit="mm")
)
# Postion and name of the title
xt = 1 - 6
yt = height + 2
Title = bquote(bold(.(title)))
# Writes the title
mat = mat +
annotate("text", x=xt, y=yt,
label=Title,
hjust=0, vjust=1,
size=6, color="#00A3A8")
### Trend ###
# For all the trend period
for (j in 1:nPeriod_trend) {
# Extracts the info to plot associated to the
# right period
Periods_trend_per =
subPeriods_trend[subNPeriod_trend == j]
NPeriods_trend_per =
subNPeriod_trend[subNPeriod_trend == j]
Var_trend_per =
subVar_trend[subNPeriod_trend == j]
Type_trend_per =
subType_trend[subNPeriod_trend == j]
Code_trend_per =
subCode_trend[subNPeriod_trend == j]
Pthresold_trend_per =
subPthresold_trend[subNPeriod_trend == j]
TrendMean_trend_per =
subTrendMean_trend[subNPeriod_trend == j]
DataMean_trend_per =
subDataMean_trend[subNPeriod_trend == j]
Fill_trend_per =
subFill_trend[subNPeriod_trend == j]
Color_trend_per =
subColor_trend[subNPeriod_trend == j]
# Converts the variable list into levels for factor
levels = unlist(Var_trend_per)
# Converts the vector of hydrological variable to
# a vector of integer associated to those variable
Xtmp = as.integer(factor(as.character(Var_trend_per),
levels=levels))
# Computes X position of the column for the period dates
Xc = j + (j - 1)*nbp*2
# Computes X positions of columns for the mean of
# variables
Xm = Xtmp + (j - 1)*nbp*2 + j
# Computes X positions of columns for the averaged trend
X = Xtmp + (j - 1)*nbp*2 + nbp + j
# Computes Y positions of each line for each station # Extracts the station for the current page
Y = as.integer(factor(Code_trend_per)) subCode = subCodefL[(slice*(iMat-1)+1):(slice*iMat)]
# Reverses vertical order of stations # Removes NA stations
Y = rev(Y) subCode = subCode[!is.na(subCode)]
# Reverses verticale order of stations
# Position of a line to delimite periods subCode = rev(subCode)
x = Xc - 0.4 # Gets the number of station for the page
xend = X[length(X)] + 0.25 nsubCode = length(subCode)
y = height + 1.1
yend = height + 1.1 # Creates logical vector to select only info about
# Drawing of the line # stations that will be plot on the page
mat = mat + CodefL_trend =
annotate("segment", Code_trend %in% subCode & Type_trend == type
x=x, xend=xend, # Extracts those info
y=y, yend=yend, subPeriods_trend = Periods_trend[CodefL_trend]
color="grey40", size=0.35) subNPeriod_trend = NPeriod_trend[CodefL_trend]
subVar_trend = Var_trend[CodefL_trend]
# Position of the name of the current period subType_trend = Type_trend[CodefL_trend]
yt = y + 0.15 subCode_trend = Code_trend[CodefL_trend]
Start = trend_period[[j]][1] subPthresold_trend = Pthresold_trend[CodefL_trend]
End = trend_period[[j]][2] subTrendMean_trend = TrendMean_trend[CodefL_trend]
# Name of the period subDataMean_trend = DataMean_trend[CodefL_trend]
periodName = bquote(bold('Période')~bold(.(as.character(j)))) subFill_trend = Fill_trend[CodefL_trend]
# Naming the period subColor_trend = Color_trend[CodefL_trend]
# Same for breaking analysis
CodefL_mean =
Code_mean %in% subCode & Type_mean == type
# Extracts right info
subPeriods_mean = Periods_mean[CodefL_mean]
subNPeriod_mean = NPeriod_mean[CodefL_mean]
subVar_mean = Var_mean[CodefL_mean]
subType_mean = Type_mean[CodefL_mean]
subCode_mean = Code_mean[CodefL_mean]
subDataMean_mean = DataMean_mean[CodefL_mean]
subBreakMean_mean = BreakMean_mean[CodefL_mean]
subFill_mean = Fill_mean[CodefL_mean]
subColor_mean = Color_mean[CodefL_mean]
# Gets the number of variable to plot in
# function of the current type
nbpMod =
length(levels(factor(subVar_trend)))
### Plot ###
# Fixes the height and width of the table according to
# the number of station and the number of column to draw
height = nsubCode
width = nbpMod * 2 * nPeriod_trend + nPeriod_trend + nPeriod_mean * nbpMod + nPeriod_mean + nbpMod
# Fixes the size of the plot area to keep proportion right
options(repr.plot.width=width, repr.plot.height=height)
# Open a new plot with a personalise theme
mat = ggplot() + theme_ash +
# Modification of theme in order to remove axis
theme(
panel.border=element_blank(),
axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank(),
plot.margin=margin(t=5, r=5, b=5, l=5, unit="mm")
)
# Extracts the name of the currently hydrological
# region plotted
title = df_meta[df_meta$code == subCode[1],]$region_hydro
subtitle = paste(' ', iMat, '/', nMat,' ', type,
sep='')
# Postion and name of the title
xt = 1 - 6
yt = height + 2
Title = bquote(bold(.(title))[.(subtitle)])
# Writes the title
mat = mat + mat = mat +
annotate("text", x=x, y=yt, annotate("text", x=xt, y=yt,
label=periodName, label=Title,
hjust=0, vjust=0.5, hjust=0, vjust=1,
size=3, color='grey40') size=6, color="#00A3A8")
# For all the variable ### Trend ###
for (i in 1:length(X)) { # For all the trend period
mat = mat + for (j in 1:nPeriod_trend) {
# Plots circles for averaged trends # Extracts the info to plot associated to the
gg_circle(r=0.45, xc=X[i], yc=Y[i], # right period
fill=Fill_trend_per[i], Periods_trend_per =
color=Color_trend_per[i]) + subPeriods_trend[subNPeriod_trend == j]
# Plots circles for averaged of variables NPeriods_trend_per =
gg_circle(r=0.45, xc=Xm[i], yc=Y[i], subNPeriod_trend[subNPeriod_trend == j]
fill='white', color='grey40') + Var_trend_per =
# Plots circles for the column of period dates subVar_trend[subNPeriod_trend == j]
gg_circle(r=0.45, xc=Xc, yc=Y[i], Type_trend_per =
fill='white', color='grey40') subType_trend[subNPeriod_trend == j]
} Code_trend_per =
# For all averaged trends on this periods subCode_trend[subNPeriod_trend == j]
for (i in 1:length(TrendMean_trend_per)) { Pthresold_trend_per =
# Extracts the value of the averaged trend subPthresold_trend[subNPeriod_trend == j]
trendMean = TrendMean_trend_per[i] TrendMean_trend_per =
# Converts it to the right format with two subTrendMean_trend[subNPeriod_trend == j]
# significant figures DataMean_trend_per =
trendMeanC = signif(trendMean*100, 2) subDataMean_trend[subNPeriod_trend == j]
Fill_trend_per =
# If it is significative subFill_trend[subNPeriod_trend == j]
if (!is.na(Pthresold_trend_per[i])) { Color_trend_per =
# The text color is white subColor_trend[subNPeriod_trend == j]
Tcolor = 'white'
# Otherwise # Converts the variable list into levels for factor
} else { levels = unlist(Var_trend_per)
# The text is grey # Converts the vector of hydrological variable to
Tcolor = 'grey85' # a vector of integer associated to those variable
} Xtmp = as.integer(factor(as.character(Var_trend_per),
levels=levels))
# Computes X position of the column for
# the period dates
Xc = j + (j - 1)*nbpMod*2
# Computes X positions of columns for
# the mean of variables
Xm = Xtmp + (j - 1)*nbpMod*2 + j
# Computes X positions of columns for
# the averaged trend
X = Xtmp + (j - 1)*nbpMod*2 + nbpMod + j
# Same for averaged variables over # Computes Y positions of each line for each station
# the current period Y = as.integer(factor(Code_trend_per))
dataMean = DataMean_trend_per[i] # Reverses vertical order of stations
dataMeanC = signif(dataMean, 2) Y = rev(Y)
# Position of a line to delimite periods
x = Xc - 0.4
xend = X[length(X)] + 0.4
y = height + 1.1
yend = height + 1.1
# Drawing of the line
mat = mat +
annotate("segment",
x=x, xend=xend,
y=y, yend=yend,
color="grey40", size=0.35)
# Position of the name of the current period
yt = y + 0.15
Start = trend_period[[j]][1]
End = trend_period[[j]][2]
# Name of the period
periodName =
bquote(bold('Période')~bold(.(as.character(j))))
# Naming the period
mat = mat + mat = mat +
# Writes the mean trend annotate("text", x=x, y=yt,
annotate('text', x=X[i], y=Y[i], label=periodName,
label=trendMeanC, hjust=0, vjust=0.5,
hjust=0.5, vjust=0.5,
size=3, color=Tcolor) +
# Writes the mean of the associated variable
annotate('text', x=Xm[i], y=Y[i],
label=dataMeanC,
hjust=0.5, vjust=0.5,
size=3, color='grey40') size=3, color='grey40')
}
# Writes a name for the period dates column
mat = mat +
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.63,
label=bquote(bold('Fin')),
hjust=0.5, vjust=0.5,
size=3, color='grey20')
# For all variable
for (i in 1:nbp) {
# Extract the variable of the plot
var = list_df2plot[[i]]$var
mat = mat +
# Writes the unit of the variable
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 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.63,
label=bquote('['*m^3*'.'*s^{-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.9,
label=expr(bar(!!var)),
hjust=0.5, vjust=0.5,
size=3.25, color='grey20')
}
# For all the station on the page # For all the variable
for (k in 1:nsubCode) { for (i in 1:length(X)) {
# Gets the code mat = mat +
code = subCode[k] # Plots circles for averaged trends
# Extracts label for the period dates gg_circle(r=0.45, xc=X[i], yc=Y[i],
label = Periods_trend_per[Code_trend_per == code][1] fill=Fill_trend_per[i],
# Gets the start and end of the period color=Color_trend_per[i]) +
# for the station # Plots circles for averaged of variables
periodStart = substr(label, 1, 4) gg_circle(r=0.45, xc=Xm[i], yc=Y[i],
periodEnd = substr(label, 14, 17) fill='white', color='grey40') +
# Plots circles for the column of period dates
gg_circle(r=0.45, xc=Xc, yc=Y[i],
fill='white', color='grey40')
}
# For all averaged trends on this periods
for (i in 1:length(TrendMean_trend_per)) {
# Extracts the value of the averaged trend
trendMean = TrendMean_trend_per[i]
# Converts it to the right format with two
# significant figures
trendMeanC = signif(trendMean*100, 2)
# If it is significative
if (!is.na(Pthresold_trend_per[i])) {
# The text color is white
Tcolor = 'white'
# Otherwise
} else {
# The text is grey
Tcolor = 'grey85'
}
# Same for averaged variables over
# the current period
dataMean = DataMean_trend_per[i]
dataMeanC = signif(dataMean, 2)
mat = mat +
# Writes the mean trend
annotate('text', x=X[i], y=Y[i],
label=trendMeanC,
hjust=0.5, vjust=0.5,
size=3, color=Tcolor) +
# Writes the mean of the associated variable
annotate('text', x=Xm[i], y=Y[i],
label=dataMeanC,
hjust=0.5, vjust=0.5,
size=3, color='grey40')
}
# Writes a name for the period dates column
mat = mat + mat = mat +
# Writes the starting value annotate('text', x=Xc, y=max(Y) + 0.9,
annotate('text', x=Xc, y=k + 0.13, label=bquote(bold('Début')),
label=bquote(bold(.(periodStart))),
hjust=0.5, vjust=0.5, hjust=0.5, vjust=0.5,
size=3, color='grey40') + size=3, color='grey20') +
# Writes the ending value annotate('text', x=Xc, y=max(Y) + 0.63,
annotate('text', x=Xc, y=k - 0.13, label=bquote(bold('Fin')),
label=bquote(bold(.(periodEnd))),
hjust=0.5, vjust=0.5, hjust=0.5, vjust=0.5,
size=3, color='grey40') size=3, color='grey20')
# For all variable
for (i in 1:nbpMod) {
# Extract the variable of the plot
var = subVar_trend[i]
mat = mat +
# Writes the unit of the variable
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 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.63,
label=bquote('['*m^3*'.'*s^{-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.9,
label=expr(bar(!!var)),
hjust=0.5, vjust=0.5,
size=3.25, color='grey20')
}
# For all the station on the page
for (k in 1:nsubCode) {
# Gets the code
code = subCode[k]
# Extracts label for the period dates
label =
Periods_trend_per[Code_trend_per == code][1]
# Gets the start and end of the period
# for the station
periodStart = substr(label, 1, 4)
periodEnd = substr(label, 14, 17)
mat = mat +
# Writes the starting value
annotate('text', x=Xc, y=k + 0.13,
label=bquote(bold(.(periodStart))),
hjust=0.5, vjust=0.5,
size=3, color='grey40') +
# Writes the ending value
annotate('text', x=Xc, y=k - 0.13,
label=bquote(bold(.(periodEnd))),
hjust=0.5, vjust=0.5,
size=3, color='grey40')
}
} }
}
### Mean ### ### Mean ###
# For all the trend period # For all the trend period
for (j in 1:nPeriod_mean) { for (j in 1:nPeriod_mean) {
# Extracts the info to plot associated to the # Extracts the info to plot associated to the
# right period # right period
Periods_mean_per = Periods_mean_per =
subPeriods_mean[subNPeriod_mean == j] subPeriods_mean[subNPeriod_mean == j]
NPeriods_mean_per = NPeriods_mean_per =
subNPeriod_mean[subNPeriod_mean == j] subNPeriod_mean[subNPeriod_mean == j]
Var_mean_per = Var_mean_per =
subVar_mean[subNPeriod_mean == j] subVar_mean[subNPeriod_mean == j]
Type_mean_per = Type_mean_per =
subType_mean[subNPeriod_mean == j] subType_mean[subNPeriod_mean == j]
Code_mean_per = Code_mean_per =
subCode_mean[subNPeriod_mean == j] subCode_mean[subNPeriod_mean == j]
DataMean_mean_per = DataMean_mean_per =
subDataMean_mean[subNPeriod_mean == j] subDataMean_mean[subNPeriod_mean == j]
BreakMean_mean_per = BreakMean_mean_per =
subBreakMean_mean[subNPeriod_mean == j] subBreakMean_mean[subNPeriod_mean == j]
Fill_mean_per = Fill_mean_per =
subFill_mean[subNPeriod_mean == j] subFill_mean[subNPeriod_mean == j]
Color_mean_per = Color_mean_per =
subColor_mean[subNPeriod_mean == j] subColor_mean[subNPeriod_mean == j]
# Converts the variable list into levels for factor # Converts the variable list into levels for factor
levels = unlist(Var_mean_per) levels = unlist(Var_mean_per)
# Converts the vector of hydrological variable to # Converts the vector of hydrological variable to
# a vector of integer associated to those variable # a vector of integer associated to those variable
Xtmp_mean = as.integer(factor(as.character(Var_mean_per), Xtmp_mean =
levels=levels)) as.integer(factor(as.character(Var_mean_per),
# Computes X position of the column for the period dates levels=levels))
Xc_mean = j + (j - 1)*nbp + X[length(X)] # Computes X position of the column for
# Computes X positions of columns for the mean of # the period dates
# variables Xc_mean = j + (j - 1)*nbpMod + X[length(X)]
Xm_mean = Xtmp_mean + (j - 1)*nbp + j + X[length(X)] # Computes X positions of columns for
# Computes X positions of columns for the difference of # the mean of variables
# mean between periods (break) Xm_mean =
Xr_mean = Xtmp_mean + (j - 1)*nbp*2 + j + X[length(X)] Xtmp_mean + (j - 1)*nbpMod + j + X[length(X)]
# Computes X positions of columns for
# Computes Y positions of each line for each station # the difference of mean between periods (break)
Y_mean = as.integer(factor(Code_mean_per)) Xr_mean =
# Reverses vertical order of stations Xtmp_mean + (j - 1)*nbpMod*2 + j + X[length(X)]
Y_mean = rev(Y_mean)
# Computes Y positions of each line for each station
# Position of a line to delimite periods Y_mean = as.integer(factor(Code_mean_per))
x = Xc_mean - 0.4 # Reverses vertical order of stations
xend = Xm_mean[length(Xm_mean)] + 0.25 Y_mean = rev(Y_mean)
y = height + 1.1
yend = height + 1.1 # Position of a line to delimite periods
# Drawing of the line x = Xc_mean - 0.4
mat = mat + xend = Xm_mean[length(Xm_mean)] + 0.25
annotate("segment", y = height + 1.1
x=x, xend=xend, yend = height + 1.1
y=y, yend=yend,
color="grey40", size=0.35)
# Position of the name of the current period
yt = y + 0.15
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))))
# Naming the period
mat = mat +
annotate("text", x=x, y=yt,
label=periodName,
hjust=0, vjust=0.5,
size=3, color='grey40')
# If this is not the first period
if (j > 1) {
# Position of a line to delimite results of
# difference of mean bewteen periods
x = Xr_mean[1] - 0.4
xend = Xr_mean[length(Xr_mean)] + 0.25
# Drawing of the line # Drawing of the line
mat = mat + mat = mat +
annotate("segment", annotate("segment",
x=x, xend=xend, x=x, xend=xend,
y=y, yend=yend, y=y, yend=yend,
color="grey40", size=0.35) 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)))) # Position of the name of the current period
# Writes the name yt = y + 0.15
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))))
# Naming the period
mat = mat + mat = mat +
annotate("text", x=x, y=yt, annotate("text", x=x, y=yt,
label=breakName, label=periodName,
hjust=0, vjust=0.5, hjust=0, vjust=0.5,
size=3, color='grey40') size=3, color='grey40')
}
# For all the variable
for (i in 1:length(Xm_mean)) {
mat = mat +
# Plots circles for averaged variables
gg_circle(r=0.45, xc=Xm_mean[i], yc=Y[i],
fill='white', color='grey40') +
# Plots circles for the column of period dates
gg_circle(r=0.45, xc=Xc_mean, yc=Y[i],
fill='white', color='grey40')
# If this is not the first period # If this is not the first period
if (j > 1) { if (j > 1) {
# Position of a line to delimite results of
# difference of mean bewteen periods
x = Xr_mean[1] - 0.4
xend = Xr_mean[length(Xr_mean)] + 0.25
# Drawing of the line
mat = mat + mat = mat +
# Plots circles for breaking results annotate("segment",
gg_circle(r=0.45, xc=Xr_mean[i], yc=Y[i], x=x, xend=xend,
fill=Fill_mean_per[i], y=y, yend=yend,
color=Color_mean_per[i]) 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))))
# Writes the name
mat = mat +
annotate("text", x=x, y=yt,
label=breakName,
hjust=0, vjust=0.5,
size=3, color='grey40')
} }
}
# For all averaged variables on this period # For all the variable
for (i in 1:length(DataMean_mean_per)) { for (i in 1:length(Xm_mean)) {
# Extracts values of averaged variables mat = mat +
dataMean = DataMean_mean_per[i] # Plots circles for averaged variables
# Converts it to the right format with two gg_circle(r=0.45, xc=Xm_mean[i], yc=Y[i],
# significant figures fill='white', color='grey40') +
dataMeanC = signif(dataMean, 2) # Plots circles for the column of period dates
# Writes averaged variables values gg_circle(r=0.45, xc=Xc_mean, yc=Y[i],
mat = mat + fill='white', color='grey40')
annotate('text', x=Xm_mean[i], y=Y[i],
label=dataMeanC, # If this is not the first period
hjust=0.5, vjust=0.5, if (j > 1) {
size=3, color='grey40') mat = mat +
# If this is not the first period # Plots circles for breaking results
if (j > 1) { gg_circle(r=0.45, xc=Xr_mean[i], yc=Y[i],
# Extracts values of breaking between periods fill=Fill_mean_per[i],
BreakMean = BreakMean_mean_per[i] color=Color_mean_per[i])
}
}
# For all averaged variables on this period
for (i in 1:length(DataMean_mean_per)) {
# Extracts values of averaged variables
dataMean = DataMean_mean_per[i]
# Converts it to the right format with two # Converts it to the right format with two
# significant figures # significant figures
BreakMeanC = signif(BreakMean*100, 2) dataMeanC = signif(dataMean, 2)
# Writes breaking values # Writes averaged variables values
mat = mat + mat = mat +
annotate('text', x=Xr_mean[i], y=Y[i], annotate('text', x=Xm_mean[i], y=Y[i],
label=BreakMeanC, label=dataMeanC,
hjust=0.5, vjust=0.5, hjust=0.5, vjust=0.5,
size=3, color='white') size=3, color='grey40')
# If this is not the first period
if (j > 1) {
# Extracts values of breaking between periods
BreakMean = BreakMean_mean_per[i]
# Converts it to the right format with two
# significant figures
BreakMeanC = signif(BreakMean*100, 2)
# Writes breaking values
mat = mat +
annotate('text', x=Xr_mean[i], y=Y[i],
label=BreakMeanC,
hjust=0.5, vjust=0.5,
size=3, color='white')
}
} }
}
# Writes a name for the period dates column # Writes a name for the period dates column
mat = mat +
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.63,
label=bquote(bold('Fin')),
hjust=0.5, vjust=0.5,
size=3, color='grey20')
# For all variables
for (i in 1:nbp) {
# Extract the variable of the plot
var = list_df2plot[[i]]$var
mat = mat + mat = mat +
# Writes the unit of the averaged variable annotate('text', x=Xc_mean, y=max(Y) + 0.9,
annotate('text', x=Xm_mean[i], y=max(Y) + 0.63, label=bquote(bold('Début')),
label=bquote('['*m^3*'.'*s^{-1}*']'),
hjust=0.5, vjust=0.5, hjust=0.5, vjust=0.5,
size=2, color='grey40') + size=3, color='grey20') +
# Writes the type of the averaged variable annotate('text', x=Xc_mean, y=max(Y) + 0.63,
annotate('text', x=Xm_mean[i], y=max(Y) + 0.9, label=bquote(bold('Fin')),
label=expr(bar(!!var)),
hjust=0.5, vjust=0.5, hjust=0.5, vjust=0.5,
size=3.25, color='grey20') size=3, color='grey20')
# If this is not the first period # For all variables
if (j > 1) { for (i in 1:nbpMod) {
# Extract the variable of the plot
var = subVar_mean[i]
mat = mat + mat = mat +
# Writes the unit of the breaking variable # Writes the unit of the averaged variable
annotate('text', x=Xr_mean[i], annotate('text',
y=max(Y) + 0.63, x=Xm_mean[i], y=max(Y) + 0.63,
label=bquote('[%]'), label=bquote('['*m^3*'.'*s^{-1}*']'),
hjust=0.5, vjust=0.5, hjust=0.5, vjust=0.5,
size=2, color='grey40') + size=2, color='grey40') +
# Writes the type of the breaking variable # Writes the type of the averaged variable
annotate('text', x=Xr_mean[i], annotate('text',
y=max(Y) + 0.9, x=Xm_mean[i], y=max(Y) + 0.9,
label=paste("d", var, sep=''), label=expr(bar(!!var)),
hjust=0.5, vjust=0.5, hjust=0.5, vjust=0.5,
size=3.25, color='grey20') size=3.25, color='grey20')
# If this is not the first period
if (j > 1) {
mat = mat +
# Writes the unit of the breaking variable
annotate('text', x=Xr_mean[i],
y=max(Y) + 0.63,
label=bquote('[%]'),
hjust=0.5, vjust=0.5,
size=2, color='grey40') +
# Writes the type of the breaking variable
annotate('text', x=Xr_mean[i],
y=max(Y) + 0.9,
label=paste("d", var, sep=''),
hjust=0.5, vjust=0.5,
size=3.25, color='grey20')
}
} }
}
# For all the station on the page # For all the station on the page
for (k in 1:nsubCode) {
# Gets the code
code = subCode[k]
# Extracts label for the period dates
label = Periods_mean_per[Code_mean_per == code][1]
# Gets the start and end of the period
# for the station
periodStart = substr(label, 1, 4)
periodEnd = substr(label, 14, 17)
mat = mat +
# # Writes the starting value
annotate('text', x=Xc_mean, y=k + 0.13,
label=bquote(bold(.(periodStart))),
hjust=0.5, vjust=0.5,
size=3, color='grey40') +
# Writes the ending value
annotate('text', x=Xc_mean, y=k - 0.13,
label=bquote(bold(.(periodEnd))),
hjust=0.5, vjust=0.5,
size=3, color='grey40')
}
}
### Code ###
# For all the station
for (k in 1:nsubCode) { for (k in 1:nsubCode) {
# Gets the code # Gets the code
code = subCode[k] code = subCode[k]
# Extracts label for the period dates # Gets the name of the station
label = Periods_mean_per[Code_mean_per == code][1] name = df_meta[df_meta$code == code,]$nom
# Gets the start and end of the period # Fixes a limit for the max number
# for the station # of characters available
periodStart = substr(label, 1, 4) ncharMax = 38
periodEnd = substr(label, 14, 17) # If the number of character of the name is greater
# than the limit
if (nchar(name) > ncharMax) {
# Cuts the name and add '...'
name = paste(substr(name, 1, ncharMax),
'...', sep='')
}
mat = mat + mat = mat +
# # Writes the starting value # Writes the code of the station
annotate('text', x=Xc_mean, y=k + 0.13, annotate('text', x=0.3, y=k + 0.14,
label=bquote(bold(.(periodStart))), label=bquote(bold(.(code))),
hjust=0.5, vjust=0.5, hjust=1, vjust=0.5,
size=3, color='grey40') + size=3.5, color="#00A3A8") +
# Writes the ending value # Writes the name of the station
annotate('text', x=Xc_mean, y=k - 0.13, annotate('text', x=0.3, y=k - 0.14,
label=bquote(bold(.(periodEnd))), label=name,
hjust=0.5, vjust=0.5, hjust=1, vjust=0.5,
size=3, color='grey40') size=3.5, color="#00A3A8")
}
}
### Code ###
# For all the station
for (k in 1:nsubCode) {
# Gets the code
code = subCode[k]
# Gets the name of the station
name = df_meta[df_meta$code == code,]$nom
# Fixes a limit for the max number
# of characters available
ncharMax = 38
# If the number of character of the name is greater
# than the limit
if (nchar(name) > ncharMax) {
# Cuts the name and add '...'
name = paste(substr(name, 1, ncharMax),
'...', sep='')
} }
### Environment ###
mat = mat + mat = mat +
# Writes the code of the station # Fixed coordinate system
annotate('text', x=0.3, y=k + 0.14, coord_fixed() +
label=bquote(bold(.(code))), # X axis
hjust=1, vjust=0.5, scale_x_continuous(limits=c(1 - rel(6),
size=3.5, color="#00A3A8") + width + rel(0.5)),
# Writes the name of the station expand=c(0, 0)) +
annotate('text', x=0.3, y=k - 0.14, # Y axis
label=name, scale_y_continuous(limits=c(1 - rel(0.5),
hjust=1, vjust=0.5, height + rel(2)),
size=3.5, color="#00A3A8") expand=c(0, 0))
}
# Paper format in A3 if needed
if (A3) {
width = 42
height = 29.7
dpi = 300
# Otherwise in A4
} else {
width = 29.7
height = 21
dpi = 100
}
### Environment ### # Saving
mat = mat + ggsave(plot=mat,
# Fixed coordinate system path=outdirTmp,
coord_fixed() + filename=paste(outnameTmp,
# X axis '_', type,
scale_x_continuous(limits=c(1 - rel(6), '_', fL,
width + rel(0.5)), iMat, sep=''),
expand=c(0, 0)) + device='pdf',
# Y axis width=width, height=height,
scale_y_continuous(limits=c(1 - rel(0.5), units='cm', dpi=dpi)
height + rel(2)),
expand=c(0, 0))
# Paper format in A3 if needed
if (A3) {
width = 42
height = 29.7
dpi = 300
# Otherwise in A4
} else {
width = 29.7
height = 21
dpi = 100
} }
}
# Saving }
ggsave(plot=mat,
path=outdirTmp,
filename=paste(outnameTmp, '_', fL,
imat, sep=''),
device='pdf',
width=width, height=height,
units='cm', dpi=dpi)
}
}
} }
...@@ -180,11 +180,15 @@ prepare_date = function(df_XEx, df_Xlist) { ...@@ -180,11 +180,15 @@ prepare_date = function(df_XEx, df_Xlist) {
# dExMean = apply(rbind(dXExUp, dXExDown), 2, mean, na.rm=TRUE) # dExMean = apply(rbind(dXExUp, dXExDown), 2, mean, na.rm=TRUE)
meanXEx_code = mean(XEx_code, na.rm=TRUE) meanXEx_code = mean(XEx_code, na.rm=TRUE)
dXEx_code = abs(XEx_code - meanXEx_code) dXEx_code = meanXEx_code - XEx_code
stdXEx_code = sd(XEx_code, na.rm=TRUE) stdXEx_code = sd(XEx_code, na.rm=TRUE)
XEx_code[dXEx_code >= stdXEx_code*3] = XEx_code[dXEx_code >= stdXEx_code*3] =
XEx_code[dXEx_code >= stdXEx_code*3] + 365 XEx_code[dXEx_code >= stdXEx_code*3] + 365
# print(group)
# print(df_XEx$datetime[df_XEx$group1 == group][dXEx_code >= stdXEx_code*3])
df_XEx$values[OkXEx_code] = XEx_code df_XEx$values[OkXEx_code] = XEx_code
} }
......
...@@ -66,7 +66,7 @@ filename = ...@@ -66,7 +66,7 @@ filename =
# ) # )
c( c(
# "S4214010_HYDRO_QJM.txt" # "S4214010_HYDRO_QJM.txt",
# "O0384010_HYDRO_QJM.txt", # "O0384010_HYDRO_QJM.txt",
"Q7002910_HYDRO_QJM.txt" "Q7002910_HYDRO_QJM.txt"
) )
...@@ -291,8 +291,8 @@ df_shapefile = ini_shapefile(computer_data_path, ...@@ -291,8 +291,8 @@ df_shapefile = ini_shapefile(computer_data_path,
### 4.2. Analysis layout ### 4.2. Analysis layout
datasheet_layout(toplot=c( datasheet_layout(toplot=c(
# 'datasheet' 'datasheet'
'matrix' # 'matrix',
# 'map' # 'map'
), ),
df_meta=df_meta, df_meta=df_meta,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment