From c989188622c0fdcfee3f295e269b692db5cd73b5 Mon Sep 17 00:00:00 2001 From: "louis.heraut" <louis.heraut@inrae.fr> Date: Fri, 17 Dec 2021 01:55:40 +0100 Subject: [PATCH] Layout --- plotting/panel.R | 76 ++++++++++++++++++++++++++++++++------------ processing/analyse.R | 1 + processing/extract.R | 3 ++ 3 files changed, 59 insertions(+), 21 deletions(-) diff --git a/plotting/panel.R b/plotting/panel.R index 995642e..af5d6f2 100644 --- a/plotting/panel.R +++ b/plotting/panel.R @@ -1319,6 +1319,7 @@ map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s lat = c() fill = c() shape = c() + trend = c() for (code in Code) { @@ -1349,11 +1350,11 @@ map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s trendMean = df_trend_code_per$trend / dataMean color_res = get_color(trendMean, - minTrendMean[idPer, i], - maxTrendMean[idPer, i], - palette_name='perso', - reverse=TRUE, - ncolor=ncolor, + minTrendMean[idPer, i], + maxTrendMean[idPer, i], + palette_name='perso', + reverse=TRUE, + ncolor=ncolor, nbTick=nbTick) if (df_trend_code_per$p <= p_threshold){ @@ -1381,6 +1382,7 @@ map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s lat = c(lat, lattmp) fill = c(fill, filltmp) shape = c(shape, shapetmp) + trend = c(trend, trendMean) } @@ -1512,7 +1514,20 @@ map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s hjust=0, vjust=0.5, size=3, color='grey40') - + + yTrend = (trend - minTrendMean[idPer, i]) / + (maxTrendMean[idPer, i] - minTrendMean[idPer, i]) * valNorm + + xTrend = rnorm(length(yTrend), mean=2, sd=0.1) + plot_trend = tibble(xTrend=xTrend, yTrend=yTrend) + + pal = pal + + geom_point(data=plot_trend, + aes(x=xTrend, y=yTrend), + shape=21, size=1, + color="grey40", fill="grey10") + + pal = pal + scale_x_continuous(limits=c(-1, 1 + 3), @@ -1524,6 +1539,9 @@ map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s theme(plot.margin=margin(t=0, r=5, b=5, l=0, unit="mm")) + + + Map = list(map, title, pal) plot = grid.arrange(grobs=Map, layout_matrix= @@ -1603,10 +1621,11 @@ info_panel = function(list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s hyd = void } + # databin = list_df2plot[[1]]$data[list_df2plot[[1]]$data$code == codeLight,] # yearLast = format(databin$Date[nrow(databin)], "%Y") # yearFirst = format(databin$Date[1], "%Y") - # Nyear = yearLast - yearFirst + 1 - + # Nyear = as.numeric(yearLast) - as.numeric(yearFirst) + 1 + map = map_panel(list_df2plot, df_meta, computer_data_path=computer_data_path, @@ -1623,7 +1642,12 @@ info_panel = function(list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s df_meta_code = df_meta[df_meta$code == codeLight,] nom = df_meta_code$nom - nom = gsub("-", "- ", nom) + nom = gsub("-", "- ", nom) + + duration = as.numeric(format(as.Date(df_meta_code$fin), "%Y")) - + as.numeric(format(as.Date(df_meta_code$debut), "%Y")) + debut = format(as.Date(df_meta_code$debut), "%d/%m/%Y") + fin = format(as.Date(df_meta_code$fin), "%d/%m/%Y") text1 = paste( "<b>", codeLight, '</b> - ', nom, @@ -1639,14 +1663,17 @@ info_panel = function(list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s text3 = paste( "<b>", "Superficie : ", df_meta_code$surface_km2_BH, " [km<sup>2</sup>] <br>", - "X = ", df_meta_code$L93X_m_BH, " [m ; Lambert 93]", + "Altitude : ", df_meta_code$altitude_m_BH, " [m]<br>", + "X = ", df_meta_code$L93X_m_BH, " [m ; Lambert 93]<br>", + "Y = ", df_meta_code$L93Y_m_BH, " [m ; Lambert 93]", "</b>", sep='') text4 = paste( "<b>", - "Altitude : ", df_meta_code$altitude_m_BH, " [m]<br>", - "Y = ", df_meta_code$L93Y_m_BH, " [m ; Lambert 93]", + "Date de début : ", debut, "<br>", + "Date de fin : ", fin, "<br>", + "Nombre d'années : ", duration, " [ans]", "</b>", sep='') @@ -1657,7 +1684,7 @@ info_panel = function(list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s gp=gpar(col="#00A3A8", fontsize=14)) gtext2 = richtext_grob(text2, - x=0, y=0.55, + x=0, y=1, margin=unit(c(t=0, r=0, b=0, l=5), "mm"), hjust=0, vjust=1, gp=gpar(col="grey20", fontsize=8)) @@ -1680,17 +1707,24 @@ info_panel = function(list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s plot.margin=margin(t=0, r=0, b=0, l=0, unit="mm")) P = list(gtext1, gtext2, gtext3, gtext4, hyd, map) - # P = list(void, void, void, void, void, void) + # P = list(void, void, void, void, void, void, void) + + LM = matrix(c(1, 1, 1, 6, + 7, 7, 7, 6, + 2, 2, 5, 6, + # 2, 2, 5, 6, + 3, 4, 5, 6, + 3, 4, 5, 6), + nrow=5, + byrow=TRUE) + heights = rep(1, times=nrow(LM)) + heights[2] = 0.1 + heights[3] = 0.8 plot = grid.arrange(grobs=P, - layout_matrix=matrix(c(1, 1, 1, 6, - 2, 2, 5, 6, - 2, 2, 5, 6, - 3, 4, 5, 6, - 3, 4, 5, 6), - nrow=5, - byrow=TRUE)) + layout_matrix=LM, + heights=heights) return(plot) } diff --git a/processing/analyse.R b/processing/analyse.R index d86cb80..9eb4f55 100644 --- a/processing/analyse.R +++ b/processing/analyse.R @@ -342,3 +342,4 @@ get_VCN10trend = function (df_data, df_meta, period, p_thresold) { + diff --git a/processing/extract.R b/processing/extract.R index e237006..b66e875 100644 --- a/processing/extract.R +++ b/processing/extract.R @@ -285,6 +285,9 @@ extract_meta = function (computer_data_path, filedir, filename, verbose=TRUE) { altitude_m_IN=as.numeric(substr(metatxt[20], 52, 63)), altitude_m_BH=as.numeric(substr(metatxt[20], 38, 50)), + + debut=substr(metatxt[25], 38, 50), + fin=substr(metatxt[25], 52, 63), statut=iStatut[trimws(substr(metatxt[26], 38, 50))], finalite=iFinalite[trimws(substr(metatxt[26], 52, 56))], -- GitLab