diff --git a/plotting/layout.R b/plotting/layout.R index 6d7f5406c72e01103bcf2700665da74d8f478e65..fa5aedb6205e1dc6e8268fc772d16f7d81e93a76 100644 --- a/plotting/layout.R +++ b/plotting/layout.R @@ -14,7 +14,7 @@ library(RColorBrewer) source('plotting/panel.R', encoding='latin1') -panels_layout = function (df_data, df_meta, layout_matrix, figdir='', filedir_opt='', filename_opt='', variable='', df_trend=NULL, p_threshold=0.1, unit2day=365.25, type='', trend_period=NULL, mean_period=NULL, axis_xlim=NULL, missRect=FALSE, time_header=NULL, info_header=TRUE, time_ratio=2, var_ratio=3) { +panels_layout = function (df_data, df_meta, layout_matrix, figdir='', filedir_opt='', filename_opt='', variable='', df_trend=NULL, p_threshold=0.1, unit2day=365.25, type='', trend_period=NULL, mean_period=NULL, axis_xlim=NULL, missRect=FALSE, time_header=NULL, info_header=TRUE, time_ratio=2, var_ratio=3, shpdir=NULL, fr_shpname=NULL, rv_shpname=NULL, computer_data_path=NULL) { outfile = "Panels" if (filename_opt != '') { @@ -378,6 +378,14 @@ panels_layout = function (df_data, df_meta, layout_matrix, figdir='', filedir_op } + + map = map_panel(computer_data_path=computer_data_path, + shpdir=shpdir, + fr_shpname=fr_shpname, + rv_shpname=rv_shpname) + + + # PDF combine pdf_combine(input=file.path(outdirTmp, list.files(outdirTmp)), output=file.path(outdir, outfile)) diff --git a/plotting/panel.R b/plotting/panel.R index 61409fb26de2bc2c5fae2aa8816887d3901bad92..fab6e0ce64b30d15160ae12d10d523a66505caf6 100644 --- a/plotting/panel.R +++ b/plotting/panel.R @@ -8,6 +8,7 @@ library(dplyr) library(grid) library(ggh4x) library(RColorBrewer) +library(rgdal) # Personal theme @@ -323,7 +324,7 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR color='grey85', size=0.15) - # For all the sub periods except the last one + # for all the sub periods except the last one for (i in 1:(nPeriod_mean-1)) { # The y limit of rectangle is the max of # the two neighboring mean step rectangle @@ -385,7 +386,7 @@ time_panel = function (df_data_code, df_trend_code, type, p_threshold=0.1, missR # Plot the data as point p = p + geom_point(aes(x=df_data_code$Date, y=df_data_code$Qm3s), - shape=21, color='grey50', fill='grey95', size=1) + shape=21, color='grey50', fill='grey97', size=1) } ### Missing data ### @@ -1025,6 +1026,53 @@ matrice_panel = function (list_df2plot, df_meta, trend_period) { } + +map_panel = function (computer_data_path, shpdir, fr_shpname, rv_shpname) { + + fr_shppath = file.path(computer_data_path, shpdir, fr_shpname) + rv_shppath = file.path(computer_data_path, shpdir, rv_shpname) + + # France + fr_spdf = readOGR(dsn=fr_shppath, verbose=FALSE) + proj4string(fr_spdf) = CRS("+proj=longlat +ellps=WGS84") + # Trasnformation en Lambert93 + france = spTransform(fr_spdf, CRS("+init=epsg:2154")) + df_france = tibble(fortify(france)) + + # Réseau hydrographique + print('aaa') + river = readOGR(dsn=rv_shppath, verbose=FALSE) + print('bbb') + river = river[which(river$Classe == 1),] + print('ccc') + df_river = tibble(fortify(river)) + + print(df_river) + + # map = ggplot() + theme_void() + + + # geom_polygon(data=df_france, + # aes(x=long, y=lat, group=group), + # color="grey40", fill="grey97", size=0.15) + + + # geom_line(data=df_river, + # aes(x=long, y=lat, group=group), + # color="grey70", size=0.25) + + + # marker color="grey50" + + # Saving matrix plot + ggsave(plot=map, + filename='map.pdf', + width=10, height=10, units='cm', dpi=100) + + return (map) +} + + + + text_panel = function(code, df_meta) { df_meta_code = df_meta[df_meta$code == code,] diff --git a/script.R b/script.R index 7a85d8c3cee62a251b6827c7880b4d63ad8839f4..a6c89c2789906a748df512812b4e8c61c10c6544 100644 --- a/script.R +++ b/script.R @@ -73,6 +73,12 @@ mean_period = list(period1, period2) p_thresold = 0.1 #c(0.01, 0.05, 0.1) +### MAP ### +shpdir = 'map' +fr_shpname = 'gadm36_FRA_0.shp' +rv_shpname = 'CoursEau_FXX.shp' + + #################################### @@ -223,22 +229,31 @@ 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), - trend_period=trend_period, - mean_period=mean_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_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), +# trend_period=trend_period, +# mean_period=mean_period, +# info_header=TRUE, +# time_header=df_data, +# time_ratio=2, +# var_ratio=3, +# computer_data_path=computer_data_path, +# shpdir=shpdir, +# fr_shpname=fr_shpname, +# rv_shpname=rv_shpname, +# figdir=figdir, +# filename_opt='') + + + +map_panel(computer_data_path, shpdir, fr_shpname, rv_shpname) + ### /!\ Removed 185 row(s) containing missing values (geom_path) -> remove NA ### diff --git a/script_install.R b/script_install.R index f5b6b55f2b0b37749bb764d9b224f21fb82b5a23..8c28e6ad37139d9f4da93eb3f9fbd66e714638dd 100644 --- a/script_install.R +++ b/script_install.R @@ -15,6 +15,11 @@ install.packages('extrafont') install.packages("RColorBrewer") install.packages('trend') +# linux +# sudo apt-get install gdal-bin proj-bin libgdal-dev libproj-dev + +install.packages("rgdal") + library(devtools) install_github("https://github.com/benRenard/BFunk") #type '1'