Commit 8967caab authored by David Carayon's avatar David Carayon
Browse files

added a new report template and new theme based on tidyquant

parent 9517e595
......@@ -2,9 +2,12 @@
export(scale_color_inrae)
export(scale_color_inrae_n5)
export(scale_colour_inrae)
export(scale_colour_inrae_n5)
export(scale_color_quant)
export(scale_fill_inrae)
export(scale_fill_inrae_n5)
export(scale_fill_quant)
export(theme_inrae)
export(theme_inrae_1)
export(theme_quant)
import(ggplot2)
import(scales)
......@@ -4,60 +4,62 @@
#' @param ...
#'
#' @return
#' @import scales
#' @export
scale_fill_inrae <- function(...){
library(scales)
discrete_scale("fill","inrae",manual_pal(values = c("#00a3a6","#275662","#66c1bf","#008c8e")), ...)
}
#' Title
#'
#' @param ...
#'
#' @return
#' @export
#' @import scales
scale_color_inrae <- function(...){
library(scales)
discrete_scale("color","inrae",manual_pal(values = c("#00a3a6","#275662","#66c1bf","#008c8e")), ...)
}
#' Title
#'
#' @param ...
#'
#' @return
#' @import scales
#' @export
scale_colour_inrae <- function(...){
library(scales)
discrete_scale("colour","inrae",manual_pal(values = c("#00a3a6","#275662","#66c1bf","#008c8e")), ...)
scale_fill_inrae_n5 <- function(...){
discrete_scale("fill","inrae",manual_pal(values = c("#275662","#008C56","#66C1BF","#9ED6E3","#C4C0B3")), ...)
}
#' Title
#'
#' @param ...
#'
#' @return
#' @import scales
#' @export
scale_fill_inrae_n5 <- function(...){
library(scales)
discrete_scale("fill","inrae",manual_pal(values = c("#275662","#008C56","#66C1BF","#9ED6E3","#C4C0B3")), ...)
scale_color_inrae_n5 <- function(...){
discrete_scale("color","inrae",manual_pal(values = c("#275662","#008C56","#66C1BF","#9ED6E3","#C4C0B3")), ...)
}
palette_light <- function() {
c(
blue = "#2c3e50", # blue
red = "#e31a1c", # red
green = "#18BC9C", # green
yellow = "#CCBE93", # yellow
steel_blue = "#a6cee3", # steel_blue
navy_blue = "#1f78b4", # navy_blue
light_green = "#b2df8a", # light_green
pink = "#fb9a99", # pink
light_orange = "#fdbf6f", # light_orange
orange = "#ff7f00", # orange
light_purple = "#cab2d6", # light_purple
purple = "#6a3d9a" # purple
) %>% toupper()
}
#' Title
......@@ -65,22 +67,25 @@ scale_fill_inrae_n5 <- function(...){
#' @param ...
#'
#' @return
#' @import scales ggplot2
#' @export
scale_color_inrae_n5 <- function(...){
library(scales)
discrete_scale("color","inrae",manual_pal(values = c("#275662","#008C56","#66C1BF","#9ED6E3","#C4C0B3")), ...)
}
scale_color_quant <- function(...) {
pal <- rep(unname(palette_light()), 100)
scale_color_manual(values = pal)
}
#' Title
#'
#' @param ...
#'
#' @return
#' @import scales ggplot2
#' @export
scale_colour_inrae_n5 <- function(...){
library(scales)
discrete_scale("colour","inrae",manual_pal(values = c("#275662","#008C56","#66C1BF","#9ED6E3","#C4C0B3")), ...)
scale_fill_quant <- function(...) {
pal <- rep(unname(palette_light()), 100)
scale_fill_manual(values = pal)
}
......@@ -153,5 +153,71 @@ theme_inrae_1 <- function(base_size = 10, base_family = "Avenir Next Pro") {
)
}
#' Title
#'
#' @param base_size base size
#' @param base_family base family
#' @import ggplot2
#'
#' @return
#' @export
theme_quant <- function(base_size = 15, base_family = "Avenir Next Pro") {
# Tidyquant colors
blue <- "#2c3e50"
green <- "#18BC9C"
white <- "#FFFFFF"
grey <- "grey80"
# Starts with theme_grey and then modify some parts
theme_grey(base_size = base_size, base_family = base_family) %+replace%
ggplot2::theme(
# Base Inherited Elements
line = ggplot2::element_line(colour = blue, size = 0.5, linetype = 1,
lineend = "butt"),
rect = ggplot2::element_rect(fill = white, colour = blue,
size = 0.5, linetype = 1),
text = ggplot2::element_text(family = base_family, face = "plain",
colour = blue, size = base_size,
lineheight = 0.9, hjust = 0.5, vjust = 0.5, angle = 0,
margin = ggplot2::margin(), debug = FALSE),
# Axes
axis.line = ggplot2::element_blank(),
axis.text = ggplot2::element_text(size = rel(0.8)),
axis.ticks = ggplot2::element_line(color = grey, size = rel(1/3)),
axis.title = ggplot2::element_text(size = rel(1.0), face = "bold"),
# Panel
panel.background = ggplot2::element_rect(fill = white, color = NA),
panel.border = ggplot2::element_rect(fill = NA, size = rel(1/2), color = blue),
panel.grid.major = ggplot2::element_line(color = grey, size = rel(1/3)),
panel.grid.minor = ggplot2::element_line(color = grey, size = rel(1/3)),
panel.grid.minor.x = ggplot2::element_blank(),
panel.spacing = ggplot2::unit(.75, "cm"),
# Legend
legend.key = ggplot2::element_rect(fill = white, color = NA),
legend.position = "top",
legend.title = element_text(face = "bold"),
# Strip (Used with multiple panels)
strip.background = ggplot2::element_rect(fill = blue, color = blue),
strip.text = ggplot2::element_text(color = white, size = ggplot2::rel(0.8), margin = ggplot2::margin(t = 5, b = 5)),
# Plot
plot.title = ggplot2::element_text(size = rel(1.2), hjust = 0,
margin = ggplot2::margin(t = 0, r = 0, b = 4, l = 0, unit = "pt")),
plot.subtitle = ggplot2::element_text(size = rel(0.9), hjust = 0,
margin = ggplot2::margin(t = 0, r = 0, b = 3, l = 0, unit = "pt")),
# Complete theme
complete = TRUE
)
}
---
title: "Titre du document"
author: "Auteur du document"
date: "Analyse du `r format(Sys.Date(), '%d %B %Y')`"
output:
pagedown::html_paged:
highlight: zenburn
css:
- "style/simple.css"
knit: pagedown::chrome_print
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = FALSE,
message = FALSE,
warning = FALSE,
dpi = 300,
out.width = 2100
)
```
```{r packages}
library(InraeThemes)
library(dplyr)
library(ggplot2)
library(gt)
source("../../../../../R/scales.R")
source("../../../../../R/themes.R")
```
```{r}
# Si besoin des couleurs
couleurs_inrae<-rgb(red=c(102,0,39,0,255,157,158,66,121,196),
green=c(193,140,86,0,255,197,214,48,120,192),
blue=c(191,86,98,0,255,68,227,137,112,179),
names=c("vert_inrae_clair","vert_inrae","vert_inrae_fonce","noir","blanc","vert","bleu_clair","bleu_fonce","gris_fonce","gris_clair"),
max= 255)
```
> Résumé de l'analyse
# Premier chapitre
## Première section
### Une sous-section
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
## Seconde section
Ci-dessous un graphique avec theme INRAE :
```{r plot}
ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point(aes(color = as.factor(gear)))+
scale_color_quant() +
facet_wrap(~am,scales="free") +
geom_smooth(color = couleurs_inrae[1]) +
labs(x = "Valeur de X", y = "Valeur de Y", title = "Titre du graphique", subtitle = "Sous-titre", color = "couleur") +
theme_quant()
```
# Second chapitre
## Première section
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
```{r gt}
iris %>%
head(10) %>%
gt() %>% tab_options(
table.width = pct(100)
)
```
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
## Seconde section
Avec insertion de code :
```{r echo = TRUE}
# On charge un package
library(ggplot2)
# On trace un graphique ggplot avec un second theme INRAE
ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
scale_fill_quant() +
geom_boxplot(color = "black") +
geom_jitter(shape = 21, color = "black", alpha = 0.6)+
labs(x = "Species", y = "Sepal Length") +
theme_quant()
```
/* DISCLAIMER : Ce travail s'appuie sur le template bénévolement produit par T. Vroylandt pour les scouts de france et mis à disposition de la communauté (tvroylandt/sgdf_pagedown)
/* Code adapté par D. Carayon (INRAE)
/* paragaphe et liste */
p, ul {
color: #000000;
font-family: "Avenir Next Pro Light";
text-align: justify;
}
/* titres */
h1, h2, h3, h4 {
color: #00a3a6;
font-family: "Avenir Next Pro Light";
font-weight: bold;
}
/* tableaux - avec gt */
/* titres */
th {
background-color: #00a3a6 !important;
color: #FFFFFF !important;
font-family: "Avenir Next Pro Light" !important;
font-weight: bold !important;
text-align: center;
border-width:1px;
border-style:solid;
border-color:black;
border-collapse:collapse;
font-size: 10pt;
}
/* colonnes de group */
.gt_group_heading {
color: #00a3a6 !important;
font-family: "Avenir Next Pro Light" !important;
font-weight: bold !important;
border-collapse:collapse;
}
table {
border-width:1px;
border-style:solid;
border-color:black;
border-collapse:collapse;
break-inside: avoid;
}
/* contenu */
td {
color: #000000;
font-family: "Avenir Next Pro Light";
border-width:1px;
border-style:solid;
text-align: center;
border-color:black;
border-collapse:collapse;
font-size: 10pt;
}
/* eviter les tableaux multipages */
.gt_table{
break-inside: avoid;
}
/* numerotation pages */
.pagedjs_margin-content{
color: #275662;
font-family: "Avenir Next Pro Light";
font-weight: bold;
}
/* ---------------------- */
/* pour l'affichage web - debug*/
/* on def les variables */
:root {
--background: whitesmoke;
--pagedjs-width: 210mm;
--pagedjs-height: 297mm;
--color-paper: white;
--color-mbox: rgba(0, 0, 0, 0.2);
--running-title-width: 2.5in;
--screen-pages-spacing: 5mm;
}
/* two pages in a row if possible on screen */
@media screen {
body {
background-color: var(--background);
margin: var(--screen-pages-spacing) auto 0 auto;
}
.pagedjs_pages {
display: flex;
max-width: calc(var(--pagedjs-width) * 2);
flex: 0;
flex-wrap: wrap;
margin: 0 auto;
}
.pagedjs_page {
background-color: var(--color-paper);
box-shadow: 0 0 0 1px var(--color-mbox);
flex-shrink: 0;
flex-grow: 0;
margin: auto auto var(--screen-pages-spacing) auto;
}
}
/* when a row can hold two pages, start first page on the right */
@media screen and (min-width: 12.32in) {
.pagedjs_page {
margin: auto 0 var(--screen-pages-spacing) 0;
}
.pagedjs_first_page {
margin-left: var(--pagedjs-width);
}
}
/* ---------------------- */
/* page size */
@page {
size: 210mm 297mm; /* var(--pagedjs-width) doesn't work in browser when printing */
}
@page :blank {
}
/* compteur de pages */
/* + footer picto */
@page chapter{
@bottom-center {
content: counter(page);
margin: 0 0 0 0;
background-color: #ffffff;
background-image: url(footer_picto_inrae.png);
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
}
/* Exception H1 pour le titre */
h1.title {
margin-block-start: -1cm;
break-after: avoid;
color: #00a3a6;
position: absolute;
bottom: 22.5cm;
left: -1cm;
text-align: left;
margin-left: 0cm;
font-size: 30pt;
}
h1.subtitle {
margin-block-start: -1cm;
break-after: avoid;
color: #00a3a6;
position: absolute;
left: -1cm;
bottom: 21cm;
text-align: left;
font-size: 20pt;
}
h2.author {
margin-block-start: 0cm;
break-after: avoid;
color: #00a3a6;
position: absolute;
left: -1cm;
top: 22cm;
text-align: left;
font-size: 20pt;
}
h2.date {
margin-block-start: -1cm;
break-after: avoid;
color: #00a3a6;
position: absolute;
bottom: 19cm;
left: -1cm;
text-align: left;
font-size: 15pt;
}
/* Page de garde */
@page :first{
margin: 0 0 0 0;
background-color: #ffffff;
background-image: url(page_avant.png);
background-repeat: no-repeat, no-repeat, no-repeat;
background-position: center, top, center;
background-size: 100%, 100%, contain;
}
/* Derniere page */
.pagedjs_page:last-of-type {
margin: 0 0 0 0;
background-color: #ffffff;
background-image: url(page_arriere.png);
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
/* page breaks; aka CSS fragmentation */
.level1 {
page: chapter;
}
.section > h1, .section > h2, .section > h3, .section > h4, .section > h5, .section > h6 {
break-after: avoid;
}
.footenotes {
break-before: always;
break-after: always;
}
.figure {
break-inside: avoid;
}
/* reset page numbering for main content */
.main .level1:first-child h1 {
counter-reset: page;
}
/* do not break captions */
caption {
break-inside: avoid;
break-after: avoid;
}
/* misc elements */
.subtitle span {
font-size: .9em;
}
img {
max-width: 100%;
}
/* verbatim */
blockquote {
break-inside: avoid;
border-style: dashed none;
border-color: #003a5d;
margin-left: 2cm;
margin-right: 2cm;
margin-block-start: 1cm !important;
}
blockquote > h1{
margin-block-start : 1cm;
}
/* pour supprimer le saut de page final */
html, body {
border: 1px solid white;
height: 99%;
page-break-after: avoid;
page-break-before: avoid;
}
/* TOC, LOT, LOF */
.toc ul, .lot ul, .lof ul {
list-style: none;
padding-left: 0;
overflow-x: hidden;
color: #000000;
font-size: 15pt;
line-height: 1.5;
break-after: avoid;
}
.toc li li {
padding-left: 1em;