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

Aes matrix

parent 43bc3fbd
No related merge requests found
Showing with 123 additions and 85 deletions
+123 -85
......@@ -204,13 +204,13 @@ panels_layout = function (df_data, df_meta, layout_matrix, figdir='', filedir_op
}
# mat = matrice_panel(list_df2plot, df_meta)
mat = matrice_panel(list_df2plot, df_meta)
# # Saving matrix plot
# ggsave(plot=mat,
# path=outdirTmp,
# filename=paste('matrix', '.pdf', sep=''),
# width=21, height=29.7, units='cm', dpi=100)
# Saving matrix plot
ggsave(plot=mat,
path=outdirTmp,
filename=paste('matrix', '.pdf', sep=''),
width=21, height=29.7, units='cm', dpi=100)
# PDF combine
pdf_combine(input=file.path(outdirTmp, list.files(outdirTmp)),
......
......@@ -217,8 +217,8 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR
x = gpct(2, codeDate, shift=TRUE)
xend = x + gpct(3, codeDate)
dy = gpct(5, codeQ, ref=0)
y = gpct(105, codeQ, ref=0) - (ii-1)*dy
dy = gpct(6, codeQ, ref=0)
y = gpct(100, codeQ, ref=0) - (ii-1)*dy
xt = xend + gpct(1, codeDate)
label = bquote(bold(.(format(df_trend_code$trend, scientific=TRUE, digits=3)))~'['*m^{3}*'.'*s^{-1}*'.'*an^{-1}*']')
......@@ -369,7 +369,7 @@ matrice_panel = function (list_df2plot, df_meta) {
Start_code = vector(mode='list', length=nCode)
End_code = vector(mode='list', length=nCode)
Code_code = vector(mode='list', length=nCode)
Period_code = vector(mode='list', length=nCode)
Periods_code = vector(mode='list', length=nCode)
df_trend = list_df2plot[[1]]$trend
......@@ -387,29 +387,28 @@ matrice_panel = function (list_df2plot, df_meta) {
nPeriod = max(length(UStart), length(UEnd))
Periods = vector(mode='list', length=nPeriod)
Periods = c()#vector(mode='list', length=nPeriod)
for (i in 1:nPeriod) {
Periods[[i]] = paste(Start[i], End[i], sep=' / ')
Periods = append(Periods,
paste(Start[i], End[i], sep=' / '))
}
Start_code[[j]] = Start
End_code[[j]] = End
Code_code[[j]] = code
Period_code[[j]] = Periods
Periods_code[[j]] = Periods
if (nPeriod > nPeriod_max) {
nPeriod_max = nPeriod
}
}
print(Code_code)
print(Period_code)
# print(Code_code)
# print(Periods_code)
######
Period_mat = c() ###
Periods_mat = c()
NPeriod_mat = c()
Type_mat = list()
Code_mat = c()
Trend_mat = c()
......@@ -425,19 +424,23 @@ matrice_panel = function (list_df2plot, df_meta) {
p_threshold = list_df2plot[[i]]$p_threshold
type = list_df2plot[[i]]$type
print(code)
# print(code)
df_trend_code = df_trend[df_trend$code == code,]
print(df_trend_code)
# print(df_trend_code)
# print(Code_code == code )
# print(Start_code)
df_trend_code_per =
df_trend_code[df_trend_code$period_start == Start[j]
& df_trend_code$period_end == End[j],]
print(Periods[[j]])
print(df_trend_code_per)
Start = Start_code[Code_code == code][[1]][j]
End = End_code[Code_code == code][[1]][j]
Periods = Periods_code[Code_code == code][[1]][j]
# print(Periods)
df_trend_code_per =
df_trend_code[df_trend_code$period_start == Start
& df_trend_code$period_end == End,]
if (df_trend_code_per$p <= p_threshold){
color_res = get_color(df_trend_code_per$trend,
......@@ -449,12 +452,15 @@ matrice_panel = function (list_df2plot, df_meta) {
color = 'white'
} else {
fill = 'white'
color = 'grey40'
color = 'grey85'
}
# print(fill)
trend = df_trend_code_per$trend
Period_mat[[j]] = Periods[[j]]
Periods_mat = append(Periods_mat, Periods)
NPeriod_mat = append(NPeriod_mat, j)
Type_mat = append(Type_mat, type)
Code_mat = append(Code_mat, code)
Trend_mat = append(Trend_mat, trend)
......@@ -466,7 +472,10 @@ matrice_panel = function (list_df2plot, df_meta) {
height = length(Code)
width = nbp * 2 * nPeriod_max
# print(height)
# print(width)
options(repr.plot.width=width, repr.plot.height=height)
mat = ggplot() +
......@@ -479,11 +488,11 @@ matrice_panel = function (list_df2plot, df_meta) {
panel.grid.major.y=element_blank(),
panel.grid.major.x=element_blank(),
axis.text.x=element_blank(),
axis.text.y=element_blank(),
# axis.text.x=element_blank(),
# axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
axis.ticks.x=element_blank(),
# axis.ticks.y=element_blank(),
# axis.ticks.x=element_blank(),
ggh4x.axis.ticks.length.minor=rel(0.5),
axis.ticks.length=unit(1.5, 'mm'),
......@@ -501,27 +510,28 @@ matrice_panel = function (list_df2plot, df_meta) {
)
X = c(0)
Y = c(0)
for (j in 1:nPeriod_max) {
print(j)
per = Periods[[j]]
Type_mat_per = Type_mat[Period_mat == per]
Code_mat_per = Code_mat[Period_mat == per]
Trend_mat_per = Trend_mat[Period_mat == per]
Fill_mat_per = Fill_mat[Period_mat == per]
Color_mat_per = Color_mat[Period_mat == per]
Type_mat_per = Type_mat[NPeriod_mat == j]
Code_mat_per = Code_mat[NPeriod_mat == j]
Trend_mat_per = Trend_mat[NPeriod_mat == j]
Fill_mat_per = Fill_mat[NPeriod_mat == j]
Color_mat_per = Color_mat[NPeriod_mat == j]
Xtmp = as.integer(factor(as.character(Type_mat_per)))
X = Xtmp + X[length(X)]
Ytmp = as.integer(factor(Code_mat_per))
Y = Ytmp + Y[length(XY)]
# print(X)
Y = as.integer(factor(Code_mat_per))
# print(Y)
for (i in 1:length(X)) {
mat = mat +
gg_circle(r=0.5, xc=X[i], yc=Y[i],
gg_circle(r=0.45, xc=X[i], yc=Y[i],
fill=Fill_mat_per[i], color=Color_mat_per[i])
}
......@@ -559,22 +569,39 @@ matrice_panel = function (list_df2plot, df_meta) {
}
}
for (i in 1:length(Code)) {
code = Code[i]
name = df_meta[df_meta$code == code,]$name
print(name)
mat = mat +
annotate('text', x=-0.5, y=i,
label=Code[i],
hjust=0, vjust=0.5,
size=3.5, color='grey40')
annotate('text', x=-1, y=i,
label=code,
hjust=0, vjust=0,
size=3.5, color='grey40') +
annotate('text', x=-1, y=i,
label=name,
hjust=0, vjust=1,
size=3.5, color='grey40')
}
# print(Y)
mat = mat +
annotate("segment",
x = width/2 + 0.5, xend = width/2 + 0.5,
y = 1 - 0.5, yend = height + 0.5,
color="grey85")
mat = mat +
coord_fixed() +
scale_x_continuous(limits=c(1 - rel(1.5),
scale_x_continuous(limits=c(1 - rel(2),
width + rel(0.5)),
expand=c(0, 0)) +
......
......@@ -2,6 +2,8 @@
library(dplyr)
library(zoo)
library(StatsAnalysisTrend)
library(lubridate)
# Sourcing R file
source('processing/format.R', encoding='latin1')
......@@ -203,7 +205,8 @@ get_QAtrend = function (df_data, period, p_thresold) {
pos.datetime=1,
na.rm=TRUE)
df_QAtrend = Estimate.stats(data.extract=df_QAEx)
df_QAtrend = Estimate.stats(data.extract=df_QAEx,
level=p_thresold)
I = interval(per[1], per[2])
if (I > Imax) {
......@@ -227,7 +230,6 @@ get_QAtrend = function (df_data, period, p_thresold) {
get_QMNAtrend = function (df_data, period, p_thresold) {
# MONTHLY MINIMUM FLOW IN THE YEAR : QMNA #
......@@ -240,10 +242,18 @@ get_QMNAtrend = function (df_data, period, p_thresold) {
df_QMNAlist = prepare(df_data, colnamegroup=c('code'))
# df_QMNAEx = extract.Var(data.station=df_QMNAlist,
# funct=mean,
# period=per,
# timestep='month',
# pos.datetime=1,
# na.rm=TRUE)
df_QMNAEx = extract.Var(data.station=df_QMNAlist,
funct=mean,
period=per,
timestep='month',
timestep='year-month',
per.start="01",
pos.datetime=1,
na.rm=TRUE)
......@@ -256,7 +266,8 @@ get_QMNAtrend = function (df_data, period, p_thresold) {
pos.datetime=1,
na.rm=TRUE)
df_QMNAtrend = Estimate.stats(data.extract=df_QMNAEx)
df_QMNAtrend = Estimate.stats(data.extract=df_QMNAEx,
level=p_thresold)
I = interval(per[1], per[2])
if (I > Imax) {
......@@ -271,7 +282,6 @@ get_QMNAtrend = function (df_data, period, p_thresold) {
df_QMNAtrendB = bind_rows(df_QMNAtrendB, df_QMNAtrend)
}
res_QMNAtrend = clean(df_QMNAtrendB, df_QMNAExB, df_QMNAlistB)
return (res_QMNAtrend)
......@@ -316,7 +326,8 @@ get_VCN10trend = function (df_data, df_meta, period, p_thresold) {
pos.datetime=1,
na.rm=TRUE)
df_VCN10trend = Estimate.stats(data.extract=df_VCN10Ex)
df_VCN10trend = Estimate.stats(data.extract=df_VCN10Ex,
level=p_thresold)
I = interval(per[1], per[2])
if (I > Imax) {
......
......@@ -176,8 +176,8 @@ df_meta = df_join$meta
res_QAtrend = get_QAtrend(df_data, period=period, p_thresold=p_thresold)
# QMNA TREND #
# res_QMNAtrend = get_QMNAtrend(df_data, period=period,
# p_thresold=p_thresold)
res_QMNAtrend = get_QMNAtrend(df_data, period=period,
p_thresold=p_thresold)
# VCN10 TREND #
res_VCN10trend = get_VCN10trend(df_data, df_meta,
......@@ -197,45 +197,45 @@ res_VCN10trend = get_VCN10trend(df_data, df_meta,
# figdir=figdir,
# filename_opt='time')
# panels_layout(list(res_QAtrend$data, res_QMNAtrend$data,
# res_VCN10trend$data),
# layout_matrix=c(1, 2, 3),
# df_meta=df_meta,
# df_trend=list(res_QAtrend$trend, res_QMNAtrend$trend,
# res_VCN10trend$trend),
# type=list(bquote(Q[A]), bquote(Q[MNA]), bquote(V[CN10])),
# missRect=list(TRUE, TRUE, TRUE),
# period=period,
# info_header=TRUE,
# time_header=df_data,
# time_ratio=2,
# var_ratio=3,
# figdir=figdir,
# filename_opt='')
panels_layout(list(res_QAtrend$data, res_VCN10trend$data),
layout_matrix=c(1, 2),
panels_layout(list(res_QAtrend$data, res_QMNAtrend$data,
res_VCN10trend$data),
layout_matrix=c(1, 2, 3),
df_meta=df_meta,
df_trend=list(res_QAtrend$trend,
df_trend=list(res_QAtrend$trend, res_QMNAtrend$trend,
res_VCN10trend$trend),
type=list(bquote(Q[A]), bquote(V[CN10])),
missRect=list(TRUE, TRUE),
type=list(bquote(Q[A]), bquote(Q[MNA]), bquote(V[CN10])),
missRect=list(TRUE, TRUE, TRUE),
period=period,
info_header=TRUE,
time_header=df_data,
time_ratio=2,
var_ratio=5,
var_ratio=3,
figdir=figdir,
filename_opt='')
# panels_layout(list(res_QAtrend$data, res_VCN10trend$data),
# layout_matrix=c(1, 2),
# df_meta=df_meta,
# df_trend=list(res_QAtrend$trend,
# res_VCN10trend$trend),
# type=list(bquote(Q[A]), bquote(V[CN10])),
# missRect=list(TRUE, TRUE),
# period=period,
# info_header=TRUE,
# time_header=df_data,
# time_ratio=2,
# var_ratio=5,
# figdir=figdir,
# filename_opt='')
# panels_layout(list(res_QAtrend$data),
# panels_layout(list(res_QMNAtrend$data),
# layout_matrix=c(1),
# df_meta=df_meta,
# df_trend=list(res_QAtrend$trend),
# type=list(bquote(Q[A])),
# df_trend=list(res_QMNAtrend$trend),
# type=list(bquote(Q[MNA])),
# missRect=list(TRUE),
# period=period,
# info_header=TRUE,
......
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