Commit d685edea authored by Heraut Louis's avatar Heraut Louis
Browse files

Plot aes colorbar

parent d4de6dcc
No related merge requests found
Showing with 71 additions and 16 deletions
+71 -16
...@@ -50,6 +50,9 @@ panel = function (df_data, df_meta, layout_matrix, figdir='', filedir_opt='', fi ...@@ -50,6 +50,9 @@ panel = function (df_data, df_meta, layout_matrix, figdir='', filedir_opt='', fi
}} }}
list_df2plot = vector(mode='list', length=nbp) list_df2plot = vector(mode='list', length=nbp)
minTrend = c()
maxTrend = c()
nokTrend = c()
for (i in 1:nbp) { for (i in 1:nbp) {
...@@ -59,6 +62,14 @@ panel = function (df_data, df_meta, layout_matrix, figdir='', filedir_opt='', fi ...@@ -59,6 +62,14 @@ panel = function (df_data, df_meta, layout_matrix, figdir='', filedir_opt='', fi
unit2day=unit2day[[i]], unit2day=unit2day[[i]],
type=type[[i]], type=type[[i]],
missRect=missRect[[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 list_df2plot[[i]] = df2plot
} }
...@@ -86,12 +97,6 @@ panel = function (df_data, df_meta, layout_matrix, figdir='', filedir_opt='', fi ...@@ -86,12 +97,6 @@ panel = function (df_data, df_meta, layout_matrix, figdir='', filedir_opt='', fi
Code = levels(factor(df_meta$code)) Code = levels(factor(df_meta$code))
nCode = length(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) { for (code in Code) {
# Print code of the station for the current plotting # 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 ...@@ -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_data_code = df_data[df_data$code == code,]
df_trend_code = df_trend[df_trend$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 = time_panel(df_data_code, df_trend_code, type=type,
p_threshold=p_threshold, missRect=missRect, p_threshold=p_threshold, missRect=missRect,
unit2day=unit2day, last=(i > nbp-nbcol)) unit2day=unit2day, last=(i > nbp-nbcol),
color=color)
P[[i+nbh]] = p P[[i+nbh]] = p
} }
...@@ -188,7 +219,7 @@ panel = function (df_data, df_meta, layout_matrix, figdir='', filedir_opt='', fi ...@@ -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)') { if (type == 'sqrt(Q)') {
...@@ -336,7 +367,7 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR ...@@ -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 (!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], abs = c(df_data_code$Date[1],
df_data_code$Date[length(df_data_code$Date)]) 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 ...@@ -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 + ord = abs_num * df_trend_code$trend +
df_trend_code$intercept df_trend_code$intercept
p = p + if (!is.null(color)) {
geom_line(aes(x=abs, y=ord), p = p +
color='cornflowerblue') 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) { ...@@ -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) palette = colorRampPalette(brewer.pal(11, palette_name))(ncolor)
if (reverse) {
palette = rev(palette)
}
idNorm = (value - min) / (max - min) idNorm = (value - min) / (max - min)
id = as.integer(idNorm*ncolor)
id = round(idNorm*(ncolor-1) + 1, 0)
print(idNorm)
print(id)
color = palette[id] color = palette[id]
return(color)
return(list(color=color, palette=palette))
} }
void = ggplot() + geom_blank(aes(1,1)) + void = ggplot() + geom_blank(aes(1,1)) +
......
...@@ -23,7 +23,7 @@ BHfiledir = ...@@ -23,7 +23,7 @@ BHfiledir =
# Name of the file that will be analysed from the BH directory # Name of the file that will be analysed from the BH directory
BHfilename = BHfilename =
# "" # ""
c("S2235610_HYDRO_QJM.txt", "P1712910_HYDRO_QJM.txt") c("S2235610_HYDRO_QJM.txt", "P1712910_HYDRO_QJM.txt", "P0885010_HYDRO_QJM.txt")
# "all" # "all"
## Or list selection ## ## Or list selection ##
......
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