Commit 3327e8cf authored by Heraut Louis's avatar Heraut Louis
Browse files

Layout

parent 7e2b3fc2
No related merge requests found
Showing with 116 additions and 40 deletions
+116 -40
...@@ -211,6 +211,8 @@ panels_layout = function (df_data, df_meta, layout_matrix, figdir='', filedir_op ...@@ -211,6 +211,8 @@ panels_layout = function (df_data, df_meta, layout_matrix, figdir='', filedir_op
P = vector(mode='list', length=nbg) P = vector(mode='list', length=nbg)
if (info_header) { if (info_header) {
time_header_code = time_header[time_header$code == code,]
Hinfo = info_panel(list_df2plot, Hinfo = info_panel(list_df2plot,
df_meta, df_meta,
computer_data_path=computer_data_path, computer_data_path=computer_data_path,
...@@ -220,7 +222,8 @@ panels_layout = function (df_data, df_meta, layout_matrix, figdir='', filedir_op ...@@ -220,7 +222,8 @@ panels_layout = function (df_data, df_meta, layout_matrix, figdir='', filedir_op
bs_shpname=bs_shpname, bs_shpname=bs_shpname,
rv_shpdir=rv_shpdir, rv_shpdir=rv_shpdir,
rv_shpname=rv_shpname, rv_shpname=rv_shpname,
codeLight=code) codeLight=code,
df_data_code=time_header_code)
P[[1]] = Hinfo P[[1]] = Hinfo
} }
...@@ -400,7 +403,8 @@ panels_layout = function (df_data, df_meta, layout_matrix, figdir='', filedir_op ...@@ -400,7 +403,8 @@ panels_layout = function (df_data, df_meta, layout_matrix, figdir='', filedir_op
bs_shpname=bs_shpname, bs_shpname=bs_shpname,
rv_shpdir=rv_shpdir, rv_shpdir=rv_shpdir,
rv_shpname=rv_shpname, rv_shpname=rv_shpname,
outdirTmp=outdirTmp) outdirTmp=outdirTmp,
margin=margin(t=5, r=0, b=5, l=5, unit="mm"))
# PDF combine # PDF combine
......
...@@ -123,7 +123,7 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR ...@@ -123,7 +123,7 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR
} }
# Open new plot # Open new plot
p = ggplot() + theme_ash p = ggplot() + theme_ash
# If it is the lats plot of the pages or not # If it is the lats plot of the pages or not
if (last) { if (last) {
...@@ -1101,7 +1101,7 @@ matrice_panel = function (list_df2plot, df_meta, trend_period, slice=NULL, outdi ...@@ -1101,7 +1101,7 @@ matrice_panel = function (list_df2plot, df_meta, trend_period, slice=NULL, outdi
map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_shpname, bs_shpdir, bs_shpname, rv_shpdir, rv_shpname, idPer=1, outdirTmp='', codeLight=NULL, margin=TRUE) { map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_shpname, bs_shpdir, bs_shpname, rv_shpdir, rv_shpname, idPer=1, outdirTmp='', codeLight=NULL, margin=NULL, showSea=TRUE) {
fr_shppath = file.path(computer_data_path, fr_shpdir, fr_shpname) fr_shppath = file.path(computer_data_path, fr_shpdir, fr_shpname)
rv_shppath = file.path(computer_data_path, rv_shpdir, rv_shpname) rv_shppath = file.path(computer_data_path, rv_shpdir, rv_shpname)
...@@ -1244,14 +1244,10 @@ map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s ...@@ -1244,14 +1244,10 @@ map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s
type = list_df2plot[[i]]$type type = list_df2plot[[i]]$type
map = ggplot() + theme_ash + map = ggplot() + theme_void() +
theme( # theme(plot.background=element_rect(fill=NA,
# panel.border=element_blank(), # color="#EC4899")) +
axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.ticks.x=element_blank(),
axis.ticks.y=element_blank()) +
coord_fixed() + coord_fixed() +
...@@ -1271,9 +1267,13 @@ map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s ...@@ -1271,9 +1267,13 @@ map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s
aes(x=long, y=lat, group=group), aes(x=long, y=lat, group=group),
color="grey40", fill=NA, size=0.2) color="grey40", fill=NA, size=0.2)
xlim = c(280000, 790000) if (showSea) {
ylim = c(6110000, 6600000) xlim = c(280000, 790000)
ylim = c(6110000, 6600000)
} else {
xlim = c(305000, 790000)
ylim = c(6135000, 6600000)
}
if (is.null(codeLight)) { if (is.null(codeLight)) {
xmin = gpct(7, xlim, shift=TRUE) xmin = gpct(7, xlim, shift=TRUE)
...@@ -1306,13 +1306,13 @@ map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s ...@@ -1306,13 +1306,13 @@ map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s
map = map + map = map +
coord_sf(xlim=xlim, ylim=ylim, coord_sf(xlim=xlim, ylim=ylim,
expand=FALSE) expand=FALSE)
if (margin) { if (is.null(margin)) {
map = map + map = map +
theme(plot.margin=margin(t=5, r=0, b=5, l=5, unit="mm")) theme(plot.margin=margin(t=0, r=0, b=0, l=0, unit="mm"))
} else { } else {
map = map + map = map +
theme(plot.margin=margin(t=0, r=0, b=0, l=0, unit="mm")) theme(plot.margin=margin)
} }
lon = c() lon = c()
...@@ -1401,13 +1401,13 @@ map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s ...@@ -1401,13 +1401,13 @@ map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s
geom_point(data=plot_map_codeNo, geom_point(data=plot_map_codeNo,
aes(x=lon, y=lat), aes(x=lon, y=lat),
shape=21, size=1, stroke=1, shape=21, size=0.5, stroke=0.5,
color='grey70', fill='grey70') + color='grey70', fill='grey97') +
geom_point(data=plot_map_code, geom_point(data=plot_map_code,
aes(x=lon, y=lat), aes(x=lon, y=lat),
shape=21, size=2, stroke=1, shape=21, size=1.5, stroke=0.5,
color='#00A3A8', fill='#00A3A8') color='grey70', fill='grey70')
} }
idTick = color_res$idTick idTick = color_res$idTick
...@@ -1543,11 +1543,71 @@ map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s ...@@ -1543,11 +1543,71 @@ map_panel = function (list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s
} }
hydrogramme = function (df_data_code, margin=NULL) {
monthData = as.numeric(format(df_data_code$Date, "%m"))
monthMean = c()
for (i in 1:12) {
data = df_data_code$Qm3s[monthData == i]
monthMean[i] = mean(data, na.rm=TRUE)
}
monthNum = 1:12
monthName = c("jan", "fv", "mar", "avr", "mai", "jun",
"jul", "ao", "sep", "oct", "nov", "dc")
monthName = factor(monthName, levels=monthName)
hyd = ggplot() + theme_ash +
theme(
# plot.background=element_rect(fill=NA, color="#EC4899"),
panel.border=element_blank(),
axis.text.x=element_text(margin=unit(c(0, 0, 0, 0), "mm"),
angle=90, vjust=0.5, hjust=1),
axis.ticks.x=element_blank(),
axis.line.y=element_line(color='grey85', size=0.3))
if (is.null(margin)) {
hyd = hyd +
theme(plot.margin=margin(t=0, r=0, b=0, l=0, unit="mm"))
} else {
hyd = hyd +
theme(plot.margin=margin)
}
hyd = hyd +
geom_bar(aes(x=monthNum, y=monthMean),
stat='identity',
fill="grey70",
width=0.75, size=0.2) +
scale_x_continuous(breaks=monthNum,
labels=monthName,
limits=c(0, max(monthNum)+0.5),
expand=c(0, 0)) +
scale_y_continuous(limits=c(0, max(monthMean)),
expand=c(0, 0))
return (hyd)
}
info_panel = function(list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_shpname, bs_shpdir, bs_shpname, rv_shpdir, rv_shpname, codeLight, df_data_code=NULL) {
if (!is.null(df_data_code)) {
hyd = hydrogramme(df_data_code,
margin=margin(t=3, r=0, b=0, l=5, unit="mm"))
} else {
hyd = void
}
info_panel = function(list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_shpname, bs_shpdir, bs_shpname, rv_shpdir, rv_shpname, codeLight) { # yearLast = format(databin$Date[nrow(databin)], "%Y")
# yearFirst = format(databin$Date[1], "%Y")
# Nyear = yearLast - yearFirst + 1
map = map_panel(list_df2plot, map = map_panel(list_df2plot,
df_meta, df_meta,
computer_data_path=computer_data_path, computer_data_path=computer_data_path,
fr_shpdir=fr_shpdir, fr_shpdir=fr_shpdir,
...@@ -1557,18 +1617,22 @@ info_panel = function(list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s ...@@ -1557,18 +1617,22 @@ info_panel = function(list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s
rv_shpdir=rv_shpdir, rv_shpdir=rv_shpdir,
rv_shpname=rv_shpname, rv_shpname=rv_shpname,
codeLight=codeLight, codeLight=codeLight,
margin=FALSE) margin=margin(t=5, r=2, b=0, l=0, unit="mm"),
showSea=FALSE)
df_meta_code = df_meta[df_meta$code == codeLight,] df_meta_code = df_meta[df_meta$code == codeLight,]
nom = df_meta_code$nom
nom = gsub("-", "- ", nom)
text1 = paste( text1 = paste(
"<b>", codeLight, '</b> - ', df_meta_code$nom, ' &#40;', "<b>", codeLight, '</b> - ', nom,
df_meta_code$region_hydro, '&#41;',
sep='') sep='')
text2 = paste( text2 = paste(
"<b>", "<b>",
"Gestionnaire : ", df_meta_code$gestionnaire, "<br>", "Gestionnaire : ", df_meta_code$gestionnaire, "<br>",
"Rgion hydro : ", df_meta_code$region_hydro,
"</b>", "</b>",
sep='') sep='')
...@@ -1588,38 +1652,46 @@ info_panel = function(list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s ...@@ -1588,38 +1652,46 @@ info_panel = function(list_df2plot, df_meta, computer_data_path, fr_shpdir, fr_s
gtext1 = richtext_grob(text1, gtext1 = richtext_grob(text1,
x=0, y=1, x=0, y=1,
margin=unit(c(t=5, r=5, b=0, l=5), "mm"), margin=unit(c(t=5, r=5, b=10, l=5), "mm"),
hjust=0, vjust=1, hjust=0, vjust=1,
gp=gpar(col="#00A3A8", fontsize=14)) gp=gpar(col="#00A3A8", fontsize=14))
gtext2 = richtext_grob(text2, gtext2 = richtext_grob(text2,
x=0, y=0.55, x=0, y=0.55,
margin=unit(c(t=0, r=5, b=0, l=5), "mm"), margin=unit(c(t=0, r=0, b=0, l=5), "mm"),
hjust=0, vjust=1, hjust=0, vjust=1,
gp=gpar(col="grey20", fontsize=8)) gp=gpar(col="grey20", fontsize=8))
gtext3 = richtext_grob(text3, gtext3 = richtext_grob(text3,
x=0, y=1, x=0, y=1,
margin=unit(c(t=0, r=5, b=5, l=5), "mm"), margin=unit(c(t=0, r=0, b=0, l=5), "mm"),
hjust=0, vjust=1, hjust=0, vjust=1,
gp=gpar(col="grey20", fontsize=9)) gp=gpar(col="grey20", fontsize=9))
gtext4 = richtext_grob(text4, gtext4 = richtext_grob(text4,
x=0, y=1, x=0, y=1,
margin=unit(c(t=0, r=5, b=5, l=5), "mm"), margin=unit(c(t=0, r=0, b=0, l=0), "mm"),
hjust=0, vjust=1, hjust=0, vjust=1,
gp=gpar(col="grey20", fontsize=9)) gp=gpar(col="grey20", fontsize=9))
P = list(gtext1, gtext2, gtext3, gtext4, map)
void = void +
theme(plot.background=element_rect(fill=NA, color="#EC4899"),
plot.margin=margin(t=0, r=0, b=0, l=0, unit="mm"))
P = list(gtext1, gtext2, gtext3, gtext4, hyd, map)
# P = list(void, void, void, void, void, void)
plot = grid.arrange(grobs=P, plot = grid.arrange(grobs=P,
layout_matrix=matrix(c(1, 1, 1, layout_matrix=matrix(c(1, 1, 1, 6,
2, 2, 5, 2, 2, 5, 6,
2, 2, 5, 2, 2, 5, 6,
3, 4, 5, 3, 4, 5, 6,
3, 4, 5), 3, 4, 5, 6),
nrow=5, nrow=5,
byrow=TRUE)) byrow=TRUE))
return(plot) return(plot)
} }
......
...@@ -264,7 +264,7 @@ panels_layout(list(res_QAtrend$data, res_QMNAtrend$data, ...@@ -264,7 +264,7 @@ panels_layout(list(res_QAtrend$data, res_QMNAtrend$data,
# map_panel(computer_data_path, # map_panel(computer_data_path,
# fr_shpdir, fr_shpname, # fr_shpdir, fr_shpname,
# bs_shpdir, bs_shpname, # bs_shpdir, bs_shpname,
# rv_shpdir, rv_shpname) # rv_shpdir, rv_s hpname)
### /!\ 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