Commit 91c10c3e authored by Heraut Louis's avatar Heraut Louis
Browse files

Cleaned and commented

parent bae48dae
No related merge requests found
Showing with 57 additions and 30 deletions
+57 -30
......@@ -452,13 +452,17 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice
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(),
......@@ -468,23 +472,22 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice
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
Type_trend_per =
subType_trend[subNPeriod_trend == j]
Code_trend_per =
......@@ -499,111 +502,135 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice
subFill_trend[subNPeriod_trend == j]
Color_trend_per =
subColor_trend[subNPeriod_trend == j]
Xtmp = as.integer(factor(as.character(Type_trend_per)))
Xc = j + (j - 1)*nbp*2
# Converts the vector of hydrological variable to
# a vector of integer associated to those variable
Xtmp = as.integer(factor(as.character(Type_trend_per)))
# Computes X position of the column of the period dates
Xc = j + (j - 1)*nbp*2
# Computes X positions of columns of the mean of
# variables
Xm = Xtmp + (j - 1)*nbp*2 + j
# Computes X positions of columns of the mean trend
X = Xtmp + (j - 1)*nbp*2 + nbp + j
# Computes Y positions of each line for each station
Y = as.integer(factor(Code_trend_per))
# Position of a line to delimite periods
x = Xc - 0.4
xend = X[length(X)] + 0.25
y = height + 1
yend = height + 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 +
annotate("text", x=x, y=yt,
label=periodName,
hjust=0, vjust=0.5,
size=3, color='grey40')
# For all the variable
for (i in 1:length(X)) {
mat = mat +
# Plots circles for mean trends
gg_circle(r=0.45, xc=X[i], yc=Y[i],
fill=Fill_trend_per[i],
color=Color_trend_per[i]) +
# Plots circles for mean of variables
gg_circle(r=0.45, xc=Xm[i], yc=Y[i],
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 the mean trend on this period
for (i in 1:length(TrendMean_trend_per)) {
# Extracts the value of the mean trend
trendMean = TrendMean_trend_per[i]
trendC = signif(trendMean*100, 2)
# 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'
}
dataMean = signif(DataMean_trend_per[i], 2)
# Same for the mean of a variable 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=trendC,
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=dataMean,
label=dataMeanC,
hjust=0.5, vjust=0.5,
size=3, color='grey40')
}
mat = mat +
# Writes a name for the period dates column
annotate('text', x=Xc, y=max(Y) + 0.85,
label=bquote(bold('Début')),
hjust=0.5, vjust=0.5,
size=3, color='grey20') +
annotate('text', x=Xc, y=max(Y) + 0.6,
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
type = list_df2plot[[i]]$type
mat = mat +
# Writes the type of the variable
annotate('text', x=X[i], y=max(Y) + 0.82,
label=bquote(.(type)),
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,
label=bquote('[%.'*ans^{-1}*']'),
hjust=0.5, vjust=0.5,
size=2, color='grey40') +
# Writes the type of the mean variable
annotate('text', x=Xm[i], y=max(Y) + 0.82,
label=bquote('µ'*.(type)),
hjust=0.5, vjust=0.5,
size=3.25, color='grey20') +
# Writes the unit of the mean variable
annotate('text', x=Xm[i], y=max(Y) + 0.6,
label=bquote('['*m^3*'.'*s^{-1}*']'),
hjust=0.5, vjust=0.5,
size=2, color='grey40')
}
# For all the station on the page
for (k in 1:nsubCode) {
# Gets the code
code = subCode[k]
......
......@@ -175,7 +175,7 @@ if (AGlistname != ""){
filename = df_selec_AG[df_selec_AG$ok,]$filename
#####
# filename = filename[(1):(25)]
# filename = filename[(1):(10)]
#####
# Extract metadata about selected stations
......
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