diff --git a/plotting/panel.R b/plotting/panel.R index 058df6f30ecfb3f8924a043eff476f997e5d5d13..8555629563abcba9c8f7ee33cba82083654d02b7 100644 --- a/plotting/panel.R +++ b/plotting/panel.R @@ -12,6 +12,15 @@ library(rgdal) library(shadowtext) +palette_perso = c('#0f3b57', + '#1d7881', + '#80c4a9', + '#e2dac6', #mid + '#fadfad', + '#d08363', + '#7e392f') + + display_type = function (type, bold=FALSE) { if (type == "QA") { @@ -1188,15 +1197,25 @@ matrice_panel = function (list_df2plot, df_meta, trend_period, mean_period, slic for (i in 1:nbp) { type = list_df2plot[[i]]$type mat = mat + - annotate('text', x=X[i], y=max(Y) + 0.7, + annotate('text', x=X[i], y=max(Y) + 0.82, label=bquote(.(type)), hjust=0.5, vjust=0.5, size=3.25, color='grey20') + - annotate('text', x=Xm[i], y=max(Y) + 0.7, + annotate('text', x=X[i], y=max(Y) + 0.6, + label=bquote('[%.'*ans^{-1}*']'), + hjust=0.5, vjust=0.5, + size=2, color='grey40') + + + annotate('text', x=Xm[i], y=max(Y) + 0.82, label=bquote('µ'*.(type)), hjust=0.5, vjust=0.5, - size=3.25, color='grey20') + size=3.25, color='grey20') + + + 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 (k in 1:nsubCode) { @@ -1338,17 +1357,28 @@ matrice_panel = function (list_df2plot, df_meta, trend_period, mean_period, slic for (i in 1:nbp) { type = list_df2plot[[i]]$type mat = mat + - annotate('text', x=Xm_mean[i], y=max(Y) + 0.7, + annotate('text', x=Xm_mean[i], y=max(Y) + 0.82, label=bquote('µ'*.(type)), hjust=0.5, vjust=0.5, - size=3.25, color='grey20') + size=3.25, color='grey20') + + + annotate('text', x=Xm_mean[i], y=max(Y) + 0.6, + label=bquote('['*m^3*'.'*s^{-1}*']'), + hjust=0.5, vjust=0.5, + size=2, color='grey40') if (j > 1) { mat = mat + - annotate('text', x=Xr_mean[i], y=max(Y) + 0.7, + annotate('text', x=Xr_mean[i], y=max(Y) + 0.82, label=bquote('d'*.(type)), hjust=0.5, vjust=0.5, - size=3.25, color='grey20') + size=3.25, color='grey20') + + + annotate('text', x=Xr_mean[i], y=max(Y) + 0.6, + label=bquote('[%]'), + hjust=0.5, vjust=0.5, + size=2, color='grey40') + } } @@ -2357,16 +2387,12 @@ cumulative = function (data_bin, df_meta, dyear=10, figdir='', filedir_opt='') { # } + + get_color = function (value, min, max, ncolor=256, palette_name='perso', reverse=FALSE) { if (palette_name == 'perso') { - colorList = c('#0f3b57', - '#1d7881', - '#80c4a9', - '#e2dac6', #mid - '#fadfad', - '#d08363', - '#7e392f') + colorList = palette_perso } else { colorList = brewer.pal(11, palette_name) } @@ -2389,13 +2415,15 @@ get_color = function (value, min, max, ncolor=256, palette_name='perso', reverse if (is.na(value)) { return (NA) } + + maxAbs = max(abs(max), abs(min)) if (value < 0) { - idNorm = (value - min) / (0 - min) + idNorm = (value + maxAbs) / maxAbs id = round(idNorm*(ncolor - 1) + 1, 0) color = palette_cold[id] } else { - idNorm = (value - 0) / (max - 0) + idNorm = value / maxAbs id = round(idNorm*(ncolor - 1) + 1, 0) color = palette_hot[id] } @@ -2407,13 +2435,7 @@ get_color = function (value, min, max, ncolor=256, palette_name='perso', reverse get_palette = function (min, max, ncolor=256, palette_name='perso', reverse=FALSE, nbTick=10) { if (palette_name == 'perso') { - colorList = c('#0f3b57', - '#1d7881', - '#80c4a9', - '#e2dac6', #mid - '#fadfad', - '#d08363', - '#7e392f') + colorList = palette_perso } else { colorList = brewer.pal(11, palette_name) } @@ -2461,7 +2483,6 @@ get_palette = function (min, max, ncolor=256, palette_name='perso', reverse=FALS - void = ggplot() + geom_blank(aes(1,1)) + theme( plot.background = element_blank(), @@ -2483,45 +2504,7 @@ palette_tester = function (n=256) { X = 1:n Y = rep(0, times=n) - palette = colorRampPalette(c( - # '#1a4157', - # '#00af9d', - # '#fbdd7e', - # '#fdb147', - # '#fd4659' - - # '#543005', - # '#8c510a', - # '#bf812d', - # '#dfc27d', - # '#f6e8c3', - # '#f5f5f5', - # '#c7eae5', - # '#80cdc1', - # '#35978f', - # '#01665e', - # '#003c30' - - '#0f3b57', - '#1d7881', - '#80c4a9', - '#e2dac6', #mid - '#fadfad', - '#d08363', - '#7e392f' - - # '#193830', - # '#2A6863', - # '#449C93', - # '#7ACEB9', - # '#BCE6DB', - # '#EFE0B0', - # '#D4B86A', - # '#B3762A', - # '#7F4A23', - # '#452C1A' - - ))(n) + palette = colorRampPalette(palette_perso)(n) p = ggplot() + diff --git a/script.R b/script.R index 90472d295fadc66711d9346c8892090becd9f472..1e75cde9f82610fe9fbadf4301f4582c4ef96c9f 100644 --- a/script.R +++ b/script.R @@ -22,15 +22,15 @@ filedir = ### MANUAL SELECTION ### # Name of the file that will be analysed from the AG directory filename = - "" + # "" - # c( - # "S2235610_HYDRO_QJM.txt", - # "P1712910_HYDRO_QJM.txt", - # "P0885010_HYDRO_QJM.txt", - # "O5055010_HYDRO_QJM.txt", - # "Q7002910_HYDRO_QJM.txt" - # ) + c( + "S2235610_HYDRO_QJM.txt", + "P1712910_HYDRO_QJM.txt", + "P0885010_HYDRO_QJM.txt", + "O5055010_HYDRO_QJM.txt", + "O0384010_HYDRO_QJM.txt" + ) # c("S4214010_HYDRO_QJM.txt", # "O0384010_HYDRO_QJM.txt", @@ -44,8 +44,8 @@ AGlistdir = "" AGlistname = - # "" - "Liste-station_RRSE.docx" + "" + # "Liste-station_RRSE.docx" ### NIVALE SELECTION ### @@ -239,8 +239,8 @@ df_shapefile = ini_shapefile(computer_data_path, fr_shpdir, fr_shpname, bs_shpdi panels_layout(isplot=c( - # 'datasheet', - # 'matrix', + 'datasheet', + 'matrix', 'map' ), df_data=list(res_QAtrend$data, res_QMNAtrend$data,