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

Plot pannel

parent 426d5392
No related merge requests found
Showing with 70 additions and 15 deletions
+70 -15
# Usefull library
library(ggplot2)
library(scales)
library(qpdf)
library(gridExtra)
# Time panel
panel = function (df_data, df_meta, figdir, p_threshold=0.1, filedir_opt='', filename_opt='', variable='', df_trend=NULL, unit2day=365.25, is_sqrt=FALSE) {
panel = function (df_data, df_meta, figdir, p_threshold=0.1, filedir_opt='', filename_opt='', variable='', df_trend=NULL, unit2day=365.25, is_sqrt=FALSE, missRect=FALSE) {
outfile = "Panels"
......@@ -42,12 +43,28 @@ panel = function (df_data, df_meta, figdir, p_threshold=0.1, filedir_opt='', fil
dDate = df_data_code$Date[length(df_data_code$Date)] -
df_data_code$Date[1]
datebreak = round(as.numeric(dDate) / unit2day / 12 , 0)
datebreak = round(as.numeric(dDate) / unit2day / 11 , 0)
p = ggplot() +
p = ggplot() + theme_bw() +
geom_line(aes(x=df_data_code$Date, y=df_data_code$Qm3s),
color='black')
if (missRect) {
NAdate = df_data_code$Date[is.na(df_data_code$Qm3s)]
dNAdate = diff(NAdate)
NAdate_Down = NAdate[append(Inf, dNAdate) != 1]
NAdate_Up = NAdate[append(dNAdate, Inf) != 1]
p = p +
geom_rect(aes(xmin=NAdate_Down,
ymin=0,
xmax=NAdate_Up,
ymax=max(df_data_code$Qm3s, na.rm=TRUE)*1.1),
linetype=0, fill='Wheat', alpha=0.3)
}
if (!is.null(df_trend)) {
if (df_trend[df_trend$code == code,]$p < p_threshold) {
......@@ -65,15 +82,52 @@ panel = function (df_data, df_meta, figdir, p_threshold=0.1, filedir_opt='', fil
}}
p = p +
ggtitle(paste(variable, 'station',
as.character(code), sep=' ')) +
# ggtitle(paste(variable, 'station',
# as.character(code), sep=' ')) +
ylab(expression(paste('débit [', m^{3}, '.',
s^{-1}, ']', sep=''))) +
xlab('date') +
scale_x_date(date_breaks=paste(as.character(datebreak), 'year', sep=' '), date_labels="%Y")
scale_x_date(date_breaks=paste(as.character(datebreak),
'year', sep=' '),
date_labels="%Y",
limits=c(min(df_data_code$Date),
max(df_data_code$Date)),
expand=c(0, 0))
if (is_sqrt) {
p = p +
scale_y_continuous(breaks=seq(0, 100, 10),
minor_breaks=seq(0, 100, 5),
limits=c(0,
max(df_data_code$Qm3s,
na.rm=TRUE)*1.1),
expand=c(0, 0))
} else {
p = p +
scale_y_continuous(breaks=seq(0, 10000, 1000),
minor_breaks=seq(0, 10000, 500),
limits=c(0,
max(df_data_code$Qm3s,
na.rm=TRUE)*1.1),
expand=c(0, 0))
}
df_meta_code = df_meta[df_meta$code == code,]
text = textGrob(paste(
'station ', code, '\n',
'nom : ', df_meta_code$nom, '\t',
'territoire : ', df_meta_code$territoire, '\n',
'position : (', df_meta_code$L93X, '; ', df_meta_code$L93Y, ')', '\t',
'surface : ', df_meta_code$surface_km2, ' km2',
sep=''),
just='left',
gp=gpar(col="darkgrey", fontsize=10))
plot = grid.arrange(text, p, ncol=1, nrow=2, heights=c(1/4, 3/4))
# Saving
ggsave(path=outdirTmp,
ggsave(plot=plot,
path=outdirTmp,
filename=paste(as.character(code), '.pdf', sep=''),
width=29.7, height=21, units='cm', dpi=100)
......
......@@ -139,8 +139,8 @@ df_meta = df_join$meta
# TIME PANEL #
# Plot time panel of debit by stations
# panel(df_data, df_meta, figdir, "")
# panel(df_data, df_meta, figdir, "", is_sqrt=TRUE)
panel(df_data, df_meta, figdir, "", missRect=TRUE)
# panel(df_data, df_meta, figdir, "", missRect=TRUE, is_sqrt=TRUE)
### /!\ Removed 185 row(s) containing missing values (geom_path) -> remove NA ###
......@@ -150,12 +150,12 @@ df_meta = df_join$meta
# QA TREND #
res_QAtrend = get_QAtrend(df_data, period)
panel(df_data=res_QAtrend$data,
df_meta=df_meta,
df_trend=res_QAtrend$trend,
p_threshold=0.1,
figdir=figdir, filedir_opt='QA', variable='QA')
# res_QAtrend = get_QAtrend(df_data, period)
# panel(df_data=res_QAtrend$data,
# df_meta=df_meta,
# df_trend=res_QAtrend$trend,
# p_threshold=0.1,
# figdir=figdir, filedir_opt='QA', variable='QA')
# QMNA TREND #
# res_QMNAtrend = get_QMNAtrend(df_data, period)
......
......@@ -8,6 +8,7 @@ install.packages("officer")
install.packages("lubridate")
install.packages('zoo')
install.packages("qpdf")
install.packages("scales")
library(devtools)
install_github("https://github.com/benRenard/BFunk") #type '1'
......
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