layout.R 24.70 KiB
# \\\
# Copyright 2021-2022 Louis Héraut*1,
#                     Éric Sauquet*2,
#                     Valentin Mansanarez
# *1   INRAE, France
#      louis.heraut@inrae.fr
# *2   INRAE, France
#      eric.sauquet@inrae.fr
# This file is part of ash R toolbox.
# Ash R toolbox is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# Ash R toolbox is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with ash R toolbox.
# If not, see <https://www.gnu.org/licenses/>.
# ///
# Rcode/plotting/layout.R
# Regroups general parameters about plotting like the theme used ang
# color management. It mainly deals with the calling to specific
# plotting functions and the organisation of each plot for the
# generation of the PDF.
# Usefull library
library(ggplot2)
library(scales)
library(qpdf)
library(gridExtra)
library(gridtext)
library(dplyr)
library(grid)
library(ggh4x)
library(RColorBrewer)
library(rgdal)
library(shadowtext)
library(png)
library(ggrepel)
# Sourcing R file
source(file.path('Rcode', 'plotting', 'datasheet.R'), encoding='UTF-8')
source(file.path('Rcode', 'plotting', 'map.R'), encoding='UTF-8')
source(file.path('Rcode', 'plotting', 'table.R'), encoding='UTF-8')
source(file.path('Rcode', 'plotting', 'break.R'), encoding='UTF-8')
source(file.path('Rcode', 'plotting', 'tools.R'), encoding='UTF-8')
## 1. PERSONALISATION ________________________________________________
### 1.1. Personal theme ______________________________________________
theme_ash =
    theme(
        # White background
        panel.background=element_rect(fill='white'),
        # Font
        text=element_text(family='sans'),
        # Border of plot
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
panel.border = element_rect(color="grey85", fill=NA, size=0.7), # Grid panel.grid.major.x=element_blank(), panel.grid.major.y=element_blank(), # Ticks marker axis.ticks.x=element_line(color='grey75', size=0.3), axis.ticks.y=element_line(color='grey75', size=0.3), # Ticks label axis.text.x=element_text(color='grey40'), axis.text.y=element_text(color='grey40'), # Ticks length axis.ticks.length=unit(1.5, 'mm'), # Ticks minor ggh4x.axis.ticks.length.minor=rel(0.5), # Title plot.title=element_blank(), # Axis title axis.title.x=element_blank(), axis.title.y=element_text(size=9, vjust=1.2, hjust=0.5, color='grey20'), # Axis line axis.line.x=element_blank(), axis.line.y=element_blank(), ) ### 1.2. Color palette _______________________________________________ palette_perso = c('#0f3b57', # cold '#1d7881', '#80c4a9', '#e2dac6', # mid '#fadfad', '#d08363', '#7e392f') # hot ## 2. USEFUL GENERICAL PLOT __________________________________________ ### 2.1. Void plot ___________________________________________________ # A plot completly blank void = ggplot() + geom_blank(aes(1,1)) + theme( plot.background = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.border = element_blank(), panel.background = element_blank(), axis.title.x = element_blank(), axis.title.y = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank(), axis.ticks = element_blank(), axis.line = element_blank() ) ### 2.2. Contour void plot ___________________________________________ # A plot completly blank with a contour contour = void + theme(plot.background=element_rect(fill=NA, color="#EC4899"), plot.margin=margin(t=0, r=0, b=0, l=0, unit="mm")) ## 3. LAYOUT _________________________________________________________ # Generates a PDF that gather datasheets, map and summarize table about the trend analyses realised on selected stations layout_panel = function (df_data, df_meta, layout_matrix, to_plot=c('datasheet', 'table', 'map'), map_to_plot=c('regime', 'trend', 'mean'), figdir='', filedir_opt='', filename_opt='', variable='', df_trend=NULL, alpha=0.1, unit2day=365.25, var='',