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

Mean period aes

parent e6045c83
No related merge requests found
Showing with 101 additions and 44 deletions
+101 -44
...@@ -285,6 +285,7 @@ panels_layout = function (df_data, df_meta, layout_matrix, figdir='', filedir_op ...@@ -285,6 +285,7 @@ panels_layout = function (df_data, df_meta, layout_matrix, figdir='', filedir_op
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,
trend_period=trend_period,
mean_period=mean_period, unit2day=unit2day, mean_period=mean_period, unit2day=unit2day,
last=(i > nbp-nbcol), color=color) last=(i > nbp-nbcol), color=color)
......
...@@ -60,7 +60,8 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR ...@@ -60,7 +60,8 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR
fill=NA, fill=NA,
size=0.7), size=0.7),
panel.grid.major.y=element_line(color='grey85', size=0.15), # panel.grid.major.y=element_line(color='grey85', size=0.15),
panel.grid.major.y=element_blank(),
panel.grid.major.x=element_blank(), panel.grid.major.x=element_blank(),
axis.ticks.y=element_line(color='grey75', size=0.3), axis.ticks.y=element_line(color='grey75', size=0.3),
...@@ -100,8 +101,31 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR ...@@ -100,8 +101,31 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR
} }
} }
if ((type == 'sqrt(Q)' | type == 'Q') & !is.null(trend_period)) { ### Sub period background ###
if (!is.null(trend_period)) {
# trend_period = as.list(trend_period)
# Imin = 10^99
# for (per in trend_period) {
# I = interval(per[1], per[2])
# if (I < Imin) {
# Imin = I
# trend_period_min = as.Date(per)
# }
# }
# p = p +
# geom_rect(aes(xmin=min(df_data_code$Date),
# ymin=0,
# xmax=trend_period_min[1],
# ymax= maxQ*1.1),
# linetype=0, fill='grey97') +
# geom_rect(aes(xmin=trend_period_min[2],
# ymin=0,
# xmax=max(df_data_code$Date),
# ymax= maxQ*1.1),
# linetype=0, fill='grey97')
trend_period = as.list(trend_period) trend_period = as.list(trend_period)
Imin = 10^99 Imin = 10^99
for (per in trend_period) { for (per in trend_period) {
...@@ -112,20 +136,85 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR ...@@ -112,20 +136,85 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR
} }
} }
idMinPer = which.min(abs(df_data_code$Date - trend_period_min[1]))
idMaxPer = which.min(abs(df_data_code$Date - trend_period_min[2]))
minPer = df_data_code$Date[idMinPer]
maxPer = df_data_code$Date[idMaxPer]
p = p + p = p +
geom_rect(aes(xmin=min(df_data_code$Date), geom_rect(aes(xmin=minPer,
ymin=0,
xmax=trend_period_min[1],
ymax= maxQ*1.1),
linetype=0, fill='grey85', alpha=0.3) +
geom_rect(aes(xmin=trend_period_min[2],
ymin=0, ymin=0,
xmax=max(df_data_code$Date), xmax=maxPer,
ymax= maxQ*1.1), ymax= maxQ*1.1),
linetype=0, fill='grey85', alpha=0.3) linetype=0, fill='grey97')
} }
### Mean step ###
if (!is.null(mean_period)) {
mean_period = as.list(mean_period)
nPeriod_mean = length(mean_period)
plot_mean = tibble()
plot_meanL = tibble()
for (j in 1:nPeriod_mean) {
Start_mean = mean_period[[j]][1]
End_mean = mean_period[[j]][2]
df_data_code_per =
df_data_code[df_data_code$Date >= Start_mean
& df_data_code$Date <= End_mean,]
xmin = min(df_data_code_per$Date)
if (xmin > min(df_data_code$Date) & j != 1) {
xmin = xmin - months(6)
}
xmax = max(df_data_code_per$Date)
if (xmax < max(df_data_code$Date) & j != nPeriod_mean) {
xmax = xmax + months(6)
}
ymax = mean(df_data_code_per$Qm3s, na.rm=TRUE)
plot_meantmp = tibble(xmin=xmin, xmax=xmax,
ymin=0, ymax=ymax, period=j)
plot_mean = bind_rows(plot_mean, plot_meantmp)
}
p = p +
geom_rect(data=plot_mean,
aes(xmin=xmin, ymin=ymin,
xmax=xmax, ymax=ymax),
linetype=0, fill='grey93')
for (i in 1:(nPeriod_mean-1)) {
yLim = max(c(plot_mean$ymax[i], plot_mean$ymax[i+1]))
xLim = plot_mean$xmax[i]
plot_lim = tibble(x=c(xLim, xLim), y=c(0, yLim))
p = p +
geom_line(data=plot_lim, aes(x=x, y=y),
linetype='b', color='grey85')
}
}
### Grid ###
xmin = min(df_data_code$Date)
xmax = max(df_data_code$Date)
ygrid = seq(0, maxQ*10, dbrk)
ord = c()
abs = c()
for (i in 1:length(ygrid)) {
ord = c(ord, rep(ygrid[i], times=2))
abs = c(abs, xmin, xmax)
}
plot_grid = tibble(abs=as.Date(abs), ord=ord)
p = p +
geom_line(data=plot_grid,
aes(x=abs, y=ord, group=ord),
color='grey85',
size=0.15)
if (type == 'sqrt(Q)' | type == 'Q') { if (type == 'sqrt(Q)' | type == 'Q') {
p = p + p = p +
geom_line(aes(x=df_data_code$Date, y=df_data_code$Qm3s), geom_line(aes(x=df_data_code$Date, y=df_data_code$Qm3s),
...@@ -151,39 +240,6 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR ...@@ -151,39 +240,6 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR
linetype=0, fill='Wheat', alpha=0.4) linetype=0, fill='Wheat', alpha=0.4)
} }
if (!is.null(mean_period)) {
mean_period = as.list(mean_period)
nPeriod_mean = length(mean_period)
for (j in 1:nPeriod_mean) {
Start_mean = mean_period[[j]][1]
End_mean = mean_period[[j]][2]
df_data_code_per =
df_data_code[df_data_code$Date >= Start_mean
& df_data_code$Date <= End_mean,]
absMin = min(df_data_code_per$Date)
if (absMin > min(df_data_code$Date)) {
absMin = absMin - months(6)
}
absMax = max(df_data_code_per$Date)
if (absMax < max(df_data_code$Date)) {
absMax = absMax + months(6)
}
abs = c(absMin, absMax)
ord = rep(mean(df_data_code_per$Qm3s, na.rm=TRUE), times=2)
plot_mean = tibble(abs=abs, ord=ord)
p = p +
geom_line(data=plot_mean, aes(x=abs, y=ord),
color='grey40', linetype='solid',
size=0.5)
}
}
if (!is.null(df_trend_code)) { if (!is.null(df_trend_code)) {
Start = df_trend_code$period_start Start = df_trend_code$period_start
......
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