diff --git a/plotting/layout.R b/plotting/layout.R index 80233e166cb465b633abcc5a41c0727d0ecbf248..b77da5a77f1b5dcc6fac02e6611f8dccf9d809d5 100644 --- a/plotting/layout.R +++ b/plotting/layout.R @@ -42,6 +42,7 @@ library(RColorBrewer) library(rgdal) library(shadowtext) + # Sourcing R file source('plotting/datasheet.R', encoding='UTF-8') source('plotting/map.R', encoding='UTF-8') diff --git a/plotting/matrix.R b/plotting/matrix.R index 4b7ef422a5ec7d52b996d58e38c6ea03b85220ba..b4e37f050b06d48523e5b275f964d11c7f9aeb4c 100644 --- a/plotting/matrix.R +++ b/plotting/matrix.R @@ -180,7 +180,8 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Blank vectors to store info about trend analyses Periods_trend = c() NPeriod_trend = c() - Var_trend = list() + Var_trend = c() + Type_trend = c() Code_trend = c() Pthresold_trend = c() TrendMean_trend = c() @@ -201,6 +202,8 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice p_threshold = list_df2plot[[i]]$p_threshold # Extract the variable of the plot var = list_df2plot[[i]]$var + # Extract the type of the variable to plot + type = list_df2plot[[i]]$type # Extracts the data corresponding to the code df_data_code = df_data[df_data$code == code,] # Extracts the trend corresponding to the code @@ -257,6 +260,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice Periods_trend = append(Periods_trend, Periods) NPeriod_trend = append(NPeriod_trend, j) Var_trend = append(Var_trend, var) + Type_trend = append(Type_trend, type) Code_trend = append(Code_trend, code) Pthresold_trend = append(Pthresold_trend, Pthresold) TrendMean_trend = append(TrendMean_trend, trendMean) @@ -272,7 +276,8 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Blank vectors to store info about breaking analysis Periods_mean = c() NPeriod_mean = c() - Var_mean = list() + Var_mean = c() + Type_mean = c() Code_mean = c() DataMean_mean = c() BreakMean_mean = c() @@ -303,6 +308,8 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice df_data = list_df2plot[[i]]$data # Extract the variable of the plot var = list_df2plot[[i]]$var + # Extract the type of the variable to plot + type = list_df2plot[[i]]$type # Extracts the data corresponding to the code df_data_code = df_data[df_data$code == code,] @@ -347,6 +354,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice Periods_mean = append(Periods_mean, Periods) NPeriod_mean = append(NPeriod_mean, j) Var_mean = append(Var_mean, var) + Type_mean = append(Type_mean, type) Code_mean = append(Code_mean, code) DataMean_mean = append(DataMean_mean, dataMean) BreakMean_mean = append(BreakMean_mean, @@ -399,6 +407,10 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice slice = nCode } + + Type = levels(factor(Type_trend)) #### + + # Extracts each possibilities of first letter of station code firstLetter = levels(factor(substr(Code, 1, 1))) # Number of different first letters @@ -436,6 +448,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice 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] @@ -449,6 +462,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice 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] @@ -502,6 +516,8 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice 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 = @@ -684,6 +700,8 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice subNPeriod_mean[subNPeriod_mean == j] Var_mean_per = subVar_mean[subNPeriod_mean == j] + Type_mean_per = + subType_mean[subNPeriod_mean == j] Code_mean_per = subCode_mean[subNPeriod_mean == j] DataMean_mean_per = @@ -838,8 +856,6 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice 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 + @@ -850,23 +866,11 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice 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=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")) - + 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') } } @@ -955,7 +959,8 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice ggsave(plot=mat, path=outdirTmp, filename=paste(outnameTmp, '_', fL, - imat, '.pdf', sep=''), + imat, sep=''), + device='pdf', width=width, height=height, units='cm', dpi=dpi) }