Commit 62e7e79c authored by Heraut Louis's avatar Heraut Louis
Browse files

Plot aes matrix

parent e2ce457b
No related merge requests found
Showing with 191 additions and 31 deletions
+191 -31
...@@ -19,14 +19,8 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR ...@@ -19,14 +19,8 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR
maxQ = max(df_data_code$Qm3s, na.rm=TRUE) maxQ = max(df_data_code$Qm3s, na.rm=TRUE)
if (maxQ > 1) { power = get_power(maxQ)
power = nchar(as.character(as.integer(maxQ))) - 1
} else {
dec = gsub('0.', '', as.character(maxQ), fixed=TRUE)
ndec = nchar(dec)
nnum = nchar(as.character(as.numeric(dec)))
power = -(ndec - nnum + 1)
}
dbrk = 10^power dbrk = 10^power
df_data_code$Qm3sN = df_data_code$Qm3s / dbrk df_data_code$Qm3sN = df_data_code$Qm3s / dbrk
...@@ -190,10 +184,10 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR ...@@ -190,10 +184,10 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR
# if (norm) { # if (norm) {
# p = p + # p = p +
# ylab(bquote('dbit ['*m^{3}*'.'*s^{-1}*'] x'~10^{.(as.character(power))})) # ylab(bquote('débit ['*m^{3}*'.'*s^{-1}*'] x'~10^{.(as.character(power))}))
# } else { # } else {
# p = p + # p = p +
# ylab(expression(paste('dbit [', m^{3}, '.', # ylab(expression(paste('débit [', m^{3}, '.',
# s^{-1}, ']', sep=''))) # s^{-1}, ']', sep='')))
# } # }
...@@ -224,7 +218,7 @@ text_panel = function(code, df_meta) { ...@@ -224,7 +218,7 @@ text_panel = function(code, df_meta) {
text = paste( text = paste(
"<span style='font-size:18pt'> station <b>", code, "</b></span><br>", "<span style='font-size:18pt'> station <b>", code, "</b></span><br>",
"nom : ", df_meta_code$nom, "<br>", "nom : ", df_meta_code$nom, "<br>",
"rgion hydrographique : ", df_meta_code$region_hydro, "<br>", "région hydrographique : ", df_meta_code$region_hydro, "<br>",
"position : (", df_meta_code$L93X, "; ", df_meta_code$L93Y, ")", "<br>", "position : (", df_meta_code$L93X, "; ", df_meta_code$L93Y, ")", "<br>",
"surface : ", df_meta_code$surface_km2, " km<sup>2</sup>", "surface : ", df_meta_code$surface_km2, " km<sup>2</sup>",
sep='') sep='')
...@@ -260,8 +254,15 @@ matrice_panel = function (list_df2plot, df_meta) { ...@@ -260,8 +254,15 @@ matrice_panel = function (list_df2plot, df_meta) {
# Get all different stations code # Get all different stations code
Code = levels(factor(df_meta$code)) Code = levels(factor(df_meta$code))
Type_mat = c() # Type = vector(mode='list', length=nbp)
# for (i in 1:nbp) {
# Type[[i]] =
# }
Type_mat = list()
Code_mat = c() Code_mat = c()
Trend_mat = c()
Fill_mat = c()
Color_mat = c() Color_mat = c()
for (code in Code) { for (code in Code) {
...@@ -271,8 +272,8 @@ matrice_panel = function (list_df2plot, df_meta) { ...@@ -271,8 +272,8 @@ matrice_panel = function (list_df2plot, df_meta) {
p_threshold = list_df2plot[[i]]$p_threshold p_threshold = list_df2plot[[i]]$p_threshold
type = list_df2plot[[i]]$type type = list_df2plot[[i]]$type
Type_mat[i] = as.character(type) Type_mat = append(Type_mat, type)
Code_mat[i] = code Code_mat = append(Code_mat, code)
df_trend_code = df_trend[df_trend$code == code,] df_trend_code = df_trend[df_trend$code == code,]
...@@ -283,18 +284,128 @@ matrice_panel = function (list_df2plot, df_meta) { ...@@ -283,18 +284,128 @@ matrice_panel = function (list_df2plot, df_meta) {
palette_name='perso', palette_name='perso',
reverse=FALSE) reverse=FALSE)
color = color_res$color trend = df_trend_code$trend
fill = color_res$color
color = 'white'
} else { } else {
trend = NA
fill = 'white'
color = 'white' color = 'white'
} }
Color_mat[i] = color Trend_mat = append(Trend_mat, trend)
Fill_mat = append(Fill_mat, fill)
Color_mat = append(Color_mat, color)
} }
} }
X = as.integer(factor(as.character(Type_mat)))
Y = as.integer(factor(Code_mat))
mat = ggplot() + mat = ggplot() +
geom_tile(aes(x=Type_mat, y=Code_mat, fill=Color_mat))
theme(
panel.background=element_rect(fill='white'),
text=element_text(family='sans'),
panel.border=element_blank(),
panel.grid.major.y=element_blank(),
panel.grid.major.x=element_blank(),
axis.text.x=element_blank(),
axis.text.y=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'),
plot.title=element_text(size=9, vjust=-3,
hjust=-1E-3, color='grey20'),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
axis.line.x=element_blank(),
axis.line.y=element_blank(),
plot.margin=margin(5, 5, 5, 5, unit="mm"),
)
# geom_point(aes(x=X, y=Y),
# shape=21, fill=Fill_mat, color=Color_mat,
# size=15, stroke=1) +
for (i in 1:length(X)) {
mat = mat +
gg_circle(r=0.5, xc=X[i], yc=Y[i], fill=Fill_mat[i], color=Color_mat[i])
}
mat = mat +
coord_fixed() +
scale_x_continuous(limits=c(min(c(X, Y)) - rel(1.5),
max(c(X, Y)) + rel(0.5)),
expand=c(0, 0)) +
scale_y_continuous(limits=c(min(c(X, Y)) - rel(0.5),
max(c(X, Y)) + rel(1)),
expand=c(0, 0))
# scale_x_continuous(limits=c(min(X)-0.4, max(X)+0.2),
# expand=c(0, 0)) +
# scale_y_continuous(limits=c(min(Y)-0.2, max(Y)+0.4),
# expand=c(0, 0))
for (i in 1:length(Code)) {
mat = mat +
annotate('text', x=-0.5, y=i,
label=Code[i],
hjust=0, vjust=0.5,
size=3.5, color='grey40')
}
for (i in 1:nbp) {
type = list_df2plot[[i]]$type
mat = mat +
annotate('text', x=i, y=max(Y) + 0.6,
label=bquote(.(type)),
hjust=0.5, vjust=0,
size=3.5, color='grey40')
}
for (i in 1:length(Trend_mat)) {
trend = Trend_mat[i]
if (!is.na(trend)) {
power = get_power(trend)
dbrk = 10^power
trendN = round(trend / dbrk, 2)
trendC1 = as.character(trendN)
trendC2 = bquote('x '*10^{.(as.character(power))})
} else {
trendC1 = ''
trendC2 = ''
}
mat = mat +
annotate('text', x=X[i], y=Y[i],
label=trendC1,
hjust=0.5, vjust=0,
size=3, color='white') +
annotate('text', x=X[i], y=Y[i],
label=trendC2,
hjust=0.5, vjust=1.3,
size=2, color='white')
}
return (mat) return (mat)
} }
...@@ -383,3 +494,26 @@ palette_tester = function () { ...@@ -383,3 +494,26 @@ palette_tester = function () {
} }
# palette_teste() # palette_teste()
get_power = function (value) {
if (value > 1) {
power = nchar(as.character(as.integer(value))) - 1
} else {
dec = gsub('0.', '', as.character(value), fixed=TRUE)
ndec = nchar(dec)
nnum = nchar(as.character(as.numeric(dec)))
power = -(ndec - nnum + 1)
}
return(power)
}
gg_circle = function(r, xc, yc, color="black", fill=NA, ...) {
x = xc + r*cos(seq(0, pi, length.out=100))
ymax = yc + r*sin(seq(0, pi, length.out=100))
ymin = yc + r*sin(seq(0, -pi, length.out=100))
annotate("ribbon", x=x, ymin=ymin, ymax=ymax, color=color, fill=fill, ...)
}
...@@ -4,7 +4,7 @@ library(zoo) ...@@ -4,7 +4,7 @@ library(zoo)
library(StatsAnalysisTrend) library(StatsAnalysisTrend)
# Sourcing R file # Sourcing R file
source('processing/format.R') source('processing/format.R', encoding='latin1')
# Compute the time gap by station # Compute the time gap by station
......
...@@ -22,9 +22,13 @@ BHfiledir = ...@@ -22,9 +22,13 @@ BHfiledir =
## Manual selection ## ## Manual selection ##
# 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", "P0885010_HYDRO_QJM.txt") # c("S2235610_HYDRO_QJM.txt",
# "all" # "P1712910_HYDRO_QJM.txt",
# "P0885010_HYDRO_QJM.txt",
# "A1000030_HYDRO_QJM.txt",
# "A2250310_HYDRO_QJM.txt"
# )
## Or list selection ## ## Or list selection ##
# Path to the list file of BH data that will be analysed # Path to the list file of BH data that will be analysed
...@@ -32,8 +36,8 @@ BHlistdir = ...@@ -32,8 +36,8 @@ BHlistdir =
"" ""
BHlistname = BHlistname =
"" # ""
# "Liste-station_RRSE.docx" "Liste-station_RRSE.docx"
### NIVALE ### ### NIVALE ###
...@@ -116,6 +120,12 @@ if (BHlistname != ""){ ...@@ -116,6 +120,12 @@ if (BHlistname != ""){
BHfilename = df_selec[df_selec$ok,]$filename BHfilename = df_selec[df_selec$ok,]$filename
} }
######
BHfilename = BHfilename[1:10]
######
# Extract metadata about selected stations # Extract metadata about selected stations
df_meta_BH = extractBH_meta(computer_data_path, BHfiledir, BHfilename) df_meta_BH = extractBH_meta(computer_data_path, BHfiledir, BHfilename)
...@@ -166,14 +176,29 @@ res_VCN10trend = get_VCN10trend(df_data, df_meta, period) ...@@ -166,14 +176,29 @@ res_VCN10trend = get_VCN10trend(df_data, df_meta, period)
# figdir=figdir, # figdir=figdir,
# filename_opt='time') # filename_opt='time')
panels_layout(list(res_QAtrend$data, res_QMNAtrend$data, # panels_layout(list(res_QAtrend$data, res_QMNAtrend$data,
res_VCN10trend$data), # res_VCN10trend$data),
layout_matrix=c(1, 2, 3), # 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,
# header_ratio=2,
# figdir=figdir,
# filename_opt='')
panels_layout(list(res_QAtrend$data, res_VCN10trend$data),
layout_matrix=c(1, 2),
df_meta=df_meta, df_meta=df_meta,
df_trend=list(res_QAtrend$trend, res_QMNAtrend$trend, df_trend=list(res_QAtrend$trend,
res_VCN10trend$trend), res_VCN10trend$trend),
type=list('Q[A]', 'Q[MNA]', 'V[CN10]'), type=list(bquote(Q[A]), bquote(V[CN10])),
missRect=list(TRUE, TRUE, TRUE), missRect=list(TRUE, TRUE),
period=period, period=period,
info_header=TRUE, info_header=TRUE,
time_header=df_data, time_header=df_data,
...@@ -181,6 +206,7 @@ panels_layout(list(res_QAtrend$data, res_QMNAtrend$data, ...@@ -181,6 +206,7 @@ panels_layout(list(res_QAtrend$data, res_QMNAtrend$data,
figdir=figdir, figdir=figdir,
filename_opt='') filename_opt='')
### /!\ Removed 185 row(s) containing missing values (geom_path) -> remove NA ### ### /!\ Removed 185 row(s) containing missing values (geom_path) -> remove NA ###
......
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