diff --git a/plotting/panel.R b/plotting/panel.R
index 7f94a6ab9a943cbcd1cb40aea79b46d0ad446d63..d7d458eb675dfd5ed423f2829d8ce2e1a19f2207 100644
--- a/plotting/panel.R
+++ b/plotting/panel.R
@@ -50,6 +50,9 @@ panel = function (df_data, df_meta, layout_matrix, figdir='', filedir_opt='', fi
         }}
 
     list_df2plot = vector(mode='list', length=nbp)
+    minTrend = c()
+    maxTrend = c()
+    nokTrend = c()
 
     for (i in 1:nbp) {
         
@@ -59,6 +62,14 @@ panel = function (df_data, df_meta, layout_matrix, figdir='', filedir_opt='', fi
                        unit2day=unit2day[[i]],
                        type=type[[i]],
                        missRect=missRect[[i]])
+        
+        okTrend = df_trend[[i]]$p[df_trend[[i]]$p <= p_threshold[[i]]]
+
+        print(okTrend)
+        
+        minTrend[i] = min(okTrend, na.rm=TRUE)
+        maxTrend[i] = max(okTrend, na.rm=TRUE)
+        nokTrend[i] = length(okTrend)
 
         list_df2plot[[i]] = df2plot
     }
@@ -86,12 +97,6 @@ panel = function (df_data, df_meta, layout_matrix, figdir='', filedir_opt='', fi
     Code = levels(factor(df_meta$code))
     nCode = length(Code)
 
-
-    # minTrend = min(list_df2plot$trend$p, na.rm=TRUE)
-    # maxTrend = max(list_df2plot$trend$p, na.rm=TRUE)
-    # get_color(value, minTrend, maxTrend, nCode, "RdYlBu")
-
-
     for (code in Code) {
         
         # Print code of the station for the current plotting
@@ -130,9 +135,35 @@ panel = function (df_data, df_meta, layout_matrix, figdir='', filedir_opt='', fi
             df_data_code = df_data[df_data$code == code,] 
             df_trend_code = df_trend[df_trend$code == code,]
 
+            if (df_trend_code$p <= p_threshold){
+                color_res = get_color(df_trend_code$p, 
+                                      minTrend[i],
+                                      maxTrend[i],
+                                      ncolor=10, 
+                                      palette_name="RdYlBu",
+                                      reverse=TRUE)
+
+                color = color_res$color
+                palette = color_res$palette
+
+            } else {            
+                color = NULL
+                palette = NULL
+            }
+
+            print(paste('min', minTrend[i]))
+            print(df_trend_code$p)
+            print(paste('max', maxTrend[i]))
+
+            if (i == 1) {print(palette)}
+            
+            print(paste('color', color))
+            print("")
+            
             p = time_panel(df_data_code, df_trend_code, type=type,
                            p_threshold=p_threshold, missRect=missRect,
-                           unit2day=unit2day, last=(i > nbp-nbcol))
+                           unit2day=unit2day, last=(i > nbp-nbcol),
+                           color=color)
 
             P[[i+nbh]] = p
         }
@@ -188,7 +219,7 @@ panel = function (df_data, df_meta, layout_matrix, figdir='', filedir_opt='', fi
 
 
 
-time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missRect=FALSE, unit2day=365.25, period=NULL, norm=TRUE, last=FALSE) {
+time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missRect=FALSE, unit2day=365.25, period=NULL, norm=TRUE, last=FALSE, color=NULL) {
 
 
     if (type == 'sqrt(Q)') {
@@ -336,7 +367,7 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR
         }
 
     if (!is.null(df_trend_code)) {
-        if (df_trend_code$p < p_threshold) {
+        if (df_trend_code$p <= p_threshold) {
 
             abs = c(df_data_code$Date[1],
                     df_data_code$Date[length(df_data_code$Date)])
@@ -346,9 +377,15 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR
             ord = abs_num * df_trend_code$trend +
                 df_trend_code$intercept
 
-            p = p + 
-                geom_line(aes(x=abs, y=ord), 
-                          color='cornflowerblue')
+            if (!is.null(color)) {
+                p = p + 
+                    geom_line(aes(x=abs, y=ord), 
+                              color=color)
+            } else {
+                p = p + 
+                    geom_line(aes(x=abs, y=ord), 
+                              color='cornflowerblue')
+            }
         }}
     
 
@@ -403,12 +440,30 @@ text_panel = function(code, df_meta) {
 
 
 
-get_color = function (value, min, max, ncolor, palette_name="RdYlBu") {
+get_color = function (value, min, max, ncolor, palette_name="RdYlBu", reverse=TRUE) {
+    
+    if (min == max) {
+        palette = colorRampPalette(brewer.pal(11, palette_name))(3)
+        color = palette[2]
+        return(list(color=color, palette=c(color)))
+    }
+
     palette = colorRampPalette(brewer.pal(11, palette_name))(ncolor)
+
+    if (reverse) {
+        palette = rev(palette)
+    }
+    
     idNorm = (value - min) / (max - min)
-    id = as.integer(idNorm*ncolor)
+    
+    id = round(idNorm*(ncolor-1) + 1, 0)
+
+    print(idNorm)
+    print(id)
+
     color = palette[id]
-    return(color)
+    
+    return(list(color=color, palette=palette))
 }
 
 void = ggplot() + geom_blank(aes(1,1)) +
diff --git a/script.R b/script.R
index 2a0fb33fb9e0558f7b60f301f4b64635a37cb525..995002351626ec239b3f31fa060f550582247fd2 100644
--- a/script.R
+++ b/script.R
@@ -23,7 +23,7 @@ BHfiledir =
 # Name of the file that will be analysed from the BH directory
 BHfilename =
     # ""
-    c("S2235610_HYDRO_QJM.txt", "P1712910_HYDRO_QJM.txt")
+    c("S2235610_HYDRO_QJM.txt", "P1712910_HYDRO_QJM.txt", "P0885010_HYDRO_QJM.txt")
     # "all"
 
 ## Or list selection ##