class: center, middle, inverse, title-slide # Scientific reporting with the
R
ecosystem ## An interactive class ### Lionel Voirol ### 30 November, 2021 --- # Objectives - Understand challenges in scientific reporting. - Understand benefits of using the `RStudio` ecosystem and `RMarkdown` for scientific reporting. - Understand which technologies interoperate when compiling a `.Rmd` file. - Acquire the ability to produce a simple scientific report using `RMarkdown` which contains essential elements (a structure, `\(\LaTeX\)` equations, code, graphs, references). - Introduction to the `xaringan` `R` package for producing scientific slides presentation with `\(\LaTeX\)` equations, code, graphs, references and interactive elements. - Introduction to the use of `Git` and `GitHub` for collaborative writing/programming and Mathpix to easily copy Math equation. - Introduction to advanced integration and customization options --- # Tools - [`R` <svg viewBox="0 0 581 512" style="height:1em;position:relative;display:inline-block;top:.1em;fill:#165CAA;" xmlns="http://www.w3.org/2000/svg"> <path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"></path></svg>](https://www.r-project.org/) - [`RStudio`](https://www.rstudio.com/) - [`RMarkdown`](https://rmarkdown.rstudio.com/) - [`xaringan` `R` package](https://github.com/yihui/xaringan) - [`GitHub`](https://github.com/) <svg viewBox="0 0 496 512" style="height:1em;position:relative;display:inline-block;top:.1em;" xmlns="http://www.w3.org/2000/svg"> <path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"></path></svg> --- # Program - Introduction - Opening and compiling a `RMarkdown (.Rmd)` document from `RStudio` and the `YAML` - Essentials elements for scientific reporting - Your turn ! (group exercise) 😱 - Tools for Scientific reporting - `xaringan` for scientific slideshows - `GitHub` - Interactive elements - Templates and advanced customization options - Your turn ! (individual exercise) 😱 - Q&A 🙋 ❓ --- # Scientific reporting ### What is scientific reporting and its challenges? **Scientific** <blockquote> conducted in the manner of science or according to results of investigation by science : practicing or using thorough or systematic methods .right[-- <cite>Merriam-Webster</cite>] </blockquote> **Report** <blockquote> give a spoken or written account of something that one has observed, heard, done, or investigated. .right[-- <cite>Merriam-Webster</cite>] </blockquote> --- class: inverse, center, middle # What elements might one wish to include in a scientific report? --- class: inverse, center, middle # What are the challenges in scientific writing that you can think of? --- # Reproducibility in Science The **replication crisis** (also called the replicability crisis or reproducibility crisis) is an ongoing methodological crisis in Science in which it has been found that many scientific studies are difficult or impossible to replicate or reproduce. <blockquote> More than 70% of researchers have tried and failed to reproduce another scientist's experiments, and more than half have failed to reproduce their own experiments. Those are some of the telling figures that emerged from Nature's survey of 1,576 researchers who took a brief online questionnaire on reproducibility in research. .right[-- <cite>Nature</cite>] </blockquote> --- # Reproducibility in Science .center[![:scale 50%](data:image/png;base64,#assets/repro.jpeg)] --- # Reproducibility in Science .center[![:scale 31%](data:image/png;base64,#assets/repro_1.jpg)] --- # Reproducibility in Science .center[![:scale 32%](data:image/png;base64,#assets/repro_2.jpg)] --- # RMarkdown `RMarkdown` (or R Markdown) is a syntax for creating documents using literate programming. This technique allows the combination of document narrative and code computation to dynamically generate documents in different formats. **This allows the creation of scientific reports that combine textual elements written by the authors with computed elements, such as visual representations or the results of a statistical analysis or data modelling. ** .center[![:scale 25%](data:image/png;base64,#assets/hex_rmd.png)] --- # RMarkdown ### Technologies <blockquote> In a nutshell, R Markdown stands on the shoulders of knitr and Pandoc. The former executes the computer code embedded in Markdown, and converts R Markdown to Markdown. The latter renders Markdown to the output format you want (such as PDF, HTML, Word, and so on). .right[-- <cite>R Markdown: The Definitive Guide</cite>] </blockquote> .center[![:scale 55%](data:image/png;base64,#assets/workflow.png)] --- class: inverse, center, middle # Essentials --- # Opening a new `RMarkdown` document in `Rstudio` <!-- .center[![:scale 60%](data:image/png;base64,#assets/x_bar_ci_estimated_sd.gif)] --> .center[![:scale 75%](data:image/png;base64,#assets/demo_rmd_2.gif)] --- # The `YAML` header The `YAML` header declare various elements of the aesthetics and compilation options of your document. - Title, author, date, ouput format ( `\(\LaTeX\)` for `.pdf`), theme, `css`, `pandoc` options, etc ```r --- title: Scientific Reporting author: Lionel Voirol date: "4/25/2021" output: html_document: css: "my_style.css" toc: true theme: united bibliography: biblio.bib --- ``` --- # Title ```r --- *title: Scientific Reporting author: Lionel Voirol date: "4/25/2021" output: html_document: css: "my_style.css" toc: true theme: united bibliography: biblio.bib --- ``` --- # Author ```r --- title: Scientific Reporting *author: Lionel Voirol date: "4/25/2021" output: html_document: css: "my_style.css" toc: true theme: united bibliography: biblio.bib --- ``` --- # Date ```r --- title: Scientific Reporting author: Lionel Voirol *date: "`r format(Sys.time(), '%d %B, %Y')`" output: html_document: css: "my_style.css" toc: true theme: united bibliography: biblio.bib --- ``` --- # Output ```r --- title: Scientific Reporting author: Lionel Voirol date: "`r format(Sys.time(), '%d %B, %Y')`" *output: * pdf_document: bibliography: biblio.bib --- ``` Since compiling a `.Rmd` document in `.pdf` requires a `\(\LaTeX\)` installation, and that you may not all have `\(\LaTeX\)` already installed, we will mostly consider compilation in `.html` for the presentation. (*Note that installing `\(\LaTeX\)` and linking it to `RStudio` is a simple and straightforward procedure and that most elements discussed today can be included in `.pdf`-compiled `RMarkdown` document*.) Find a detailed procedure to install the [`tinytex`](https://yihui.org/tinytex/) `\(\LaTeX\)` distribution at this webpage [Install LaTeX (TinyTeX) for PDF reports](https://bookdown.org/yihui/rmarkdown-cookbook/install-latex.html) (required if you want to do the project with `RMarkdown`). --- # Structure ```r # Header 1 ## Header 2 ### Header 3 ``` # Header 1 ## Header 2 ### Header 3 --- # Table of content A table of content (`toc`) can be included with the `YAML` option `toc: true`. ```r --- title: "demo" author: "Lionel Voirol" date: "4/25/2021" output: html_document: * toc: true theme: united --- ``` Which will produce, depending on the specified styling and other parameters: .center[![:scale 15%](data:image/png;base64,#assets/toc_1.png)] --- # Text styling Use `*` or `_` to emphasize things: ```r **this is in italic* and _so is this_ ***this is in bold** and __so is this__ ****this is bold and italic*** and ___so is this___ ``` *this is in italic* and _so is this_ **this is in bold** and __so is this__ ***this is bold and italic*** and ___so is this___ --- # Lists ```r - The - character start an unsorted list. + or you can also use the + character or the - character To start an ordered list, write this: 1. this starts a list *with* numbers 2. this will show as number '2.' 53. a wrong number here still shows as number '3.' ``` - The - character start an unsorted list. + or you can also use the + character or the - character To start an ordered list, write this: 1. this starts a list *with* numbers 2. this will show as number '2.' 33. a wrong number here still shows as number '3.' --- # Tables You can align text in the columns to the left, right, or center by adding a colon (:) to the left, right, or on both side of the hyphens within the header row. ```r | Syntax | Description | Test Text | | :--- | :----: | ---: | | Header | Title | Here's this | | Paragraph | Text | And more | ``` | Syntax | Description | Test Text | | :--- | :----: | ---: | | Header | Title | Here's this | | Paragraph | Text | And more | --- # Printing an output as a table with `knitr::kable()` ```r data("iris") knitr::kable(iris[1:5,]) ``` | Sepal.Length| Sepal.Width| Petal.Length| Petal.Width|Species | |------------:|-----------:|------------:|-----------:|:-------| | 5.1| 3.5| 1.4| 0.2|setosa | | 4.9| 3.0| 1.4| 0.2|setosa | | 4.7| 3.2| 1.3| 0.2|setosa | | 4.6| 3.1| 1.5| 0.2|setosa | | 5.0| 3.6| 1.4| 0.2|setosa | There are many more options that can be set to have particularly good looking table with the `knitr` and `kableExtra` packages ([see here for a detailled documentation](https://bookdown.org/yihui/rmarkdown-cookbook/kable.html)). --- # Extended table options with `knitr::kable()` and `kableExtra` ```r library(kableExtra) mtcars[1:3, 1:8] %>% kbl() %>% kable_paper(full_width = F) %>% column_spec(2, color = spec_color(mtcars$mpg[1:3]), link = "https://haozhu233.github.io/kableExtra/") %>% column_spec(6, color = "white", background = spec_color(mtcars$drat[1:3], end = 0.7), popover = paste("am:", mtcars$am[1:3])) ``` <table class=" lightable-paper" style='font-family: "Arial Narrow", arial, helvetica, sans-serif; width: auto !important; margin-left: auto; margin-right: auto;'> <thead> <tr> <th style="text-align:left;"> </th> <th style="text-align:right;"> mpg </th> <th style="text-align:right;"> cyl </th> <th style="text-align:right;"> disp </th> <th style="text-align:right;"> hp </th> <th style="text-align:right;"> drat </th> <th style="text-align:right;"> wt </th> <th style="text-align:right;"> qsec </th> <th style="text-align:right;"> vs </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Mazda RX4 </td> <td style="text-align:right;color: rgba(68, 1, 84, 1) !important;"> <a href="https://haozhu233.github.io/kableExtra/" style="color: rgba(68, 1, 84, 1) !important;"> 21.0 </a> </td> <td style="text-align:right;"> 6 </td> <td style="text-align:right;"> 160 </td> <td style="text-align:right;"> 110 </td> <td style="text-align:right;color: white !important;background-color: rgba(67, 191, 113, 1) !important;" data-toggle="popover" data-container="body" data-trigger="hover" data-placement="right" data-content="am: 1"> 3.90 </td> <td style="text-align:right;"> 2.620 </td> <td style="text-align:right;"> 16.46 </td> <td style="text-align:right;"> 0 </td> </tr> <tr> <td style="text-align:left;"> Mazda RX4 Wag </td> <td style="text-align:right;color: rgba(68, 1, 84, 1) !important;"> <a href="https://haozhu233.github.io/kableExtra/" style="color: rgba(68, 1, 84, 1) !important;"> 21.0 </a> </td> <td style="text-align:right;"> 6 </td> <td style="text-align:right;"> 160 </td> <td style="text-align:right;"> 110 </td> <td style="text-align:right;color: white !important;background-color: rgba(67, 191, 113, 1) !important;" data-toggle="popover" data-container="body" data-trigger="hover" data-placement="right" data-content="am: 1"> 3.90 </td> <td style="text-align:right;"> 2.875 </td> <td style="text-align:right;"> 17.02 </td> <td style="text-align:right;"> 0 </td> </tr> <tr> <td style="text-align:left;"> Datsun 710 </td> <td style="text-align:right;color: rgba(253, 231, 37, 1) !important;"> <a href="https://haozhu233.github.io/kableExtra/" style="color: rgba(253, 231, 37, 1) !important;"> 22.8 </a> </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 108 </td> <td style="text-align:right;"> 93 </td> <td style="text-align:right;color: white !important;background-color: rgba(68, 1, 84, 1) !important;" data-toggle="popover" data-container="body" data-trigger="hover" data-placement="right" data-content="am: 1"> 3.85 </td> <td style="text-align:right;"> 2.320 </td> <td style="text-align:right;"> 18.61 </td> <td style="text-align:right;"> 1 </td> </tr> </tbody> </table> --- # `\(\LaTeX\)` support `\(\LaTeX\)` is a software system for document preparation which facilitates the writing of complex mathematical formula. ### Centered Equation ```r $$ f(x)=\frac{1}{\sigma \sqrt{2 \pi}} \mathrm{e}^{-\frac{1}{2}\left(\frac{x-\mu}{\sigma}\right)^{2}} $$ ``` $$ f(x)=\frac{1}{\sigma \sqrt{2 \pi}} \mathrm{e}^{-\frac{1}{2}\left(\frac{x-\mu}{\sigma}\right)^{2}} $$ ### Inline equation ```r Hence, we consider the vector $\boldsymbol{\theta} \in \boldsymbol{\Theta}$ ``` Hence, we consider the vector `\(\boldsymbol{\theta} \in \boldsymbol{\Theta}\)` --- # Essential `\(\LaTeX\)` commands .center[![:scale 75%](data:image/png;base64,#assets/latex1.png)] Find an introduction to `\(\LaTeX\)` [here](https://www.pcc.edu/instructional-support/accessibility/mathscience/latex/) and a non exhaustive list of `\(\LaTeX\)` symbols [here](https://oeis.org/wiki/List_of_LaTeX_mathematical_symbols). --- # Inline `R` code and `R` code chunks ```r *The upper and lower confidence intervals are `r res_1` and `r res 2`. ``` The upper and lower confidence intervals are 12.68 and 14.56. ```r set.seed(123) data = rnorm(500) mean_x = mean(data) hist(data) ``` <img src="data:image/png;base64,#index_files/figure-html/unnamed-chunk-18-1.png" style="display: block; margin: auto;" /> --- # `knitr` options In a `.Rmd` document, you can specify multiple chunk option in the ````{r}` header of a `R` chunk of code. Chunk options are written in the form `tag=value` like `echo=T`. Find an exhaustive list of `knitr` options [here](https://yihui.org/knitr/options/#chunk-options).): | `knitr` chunk option | Description | | :--- | :--- | | `echo` | Whether to echo the source code in the output document (someone may not prefer reading your smart source code but only results). | | `eval` | Whether to evaluate a code chunk. | | `results` | When set to 'hide', text output will be hidden; when set to 'asis', text output is written “as-is,” | | `cache` | Whether to enable caching. If caching is enabled, the same code chunk will not be evaluated the next time the document is compiled (if the code chunk was not modified), which can save you time. | | `fig.align`, `fig.width` & `fig.height` | The (graphical device) size of R plots in inches. | --- # Bibliography - Save a file in the same directory of your `.Rmd` file with extension `.bib`. - Reference this file in the `YAML`. For example considering the file `biblio.bib` ```r --- title: Scientific Reporting author: Lionel Voirol date: "`r format(Sys.time(), '%d %B, %Y')`" output: html_document: css: "my_style.css" toc: true theme: united *bibliography: biblio.bib --- ``` You can then insert citation as such: ```r "L'absurdité est surtout le divorce de l'homme et du monde." @camus1972etranger ``` --- # Bibliography ### Copying `.bib` references from Google Scholar .center[![:scale 75%](data:image/png;base64,#assets/bib_copy.gif)] --- # Images ```r ![](assets/random_number_generator_2.png) ``` .center[![:scale 90%](data:image/png;base64,#assets/random_number_generator_2.png)] --- # Emojis and icons ```r `r emo::ji('alien')` `r emo::ji('sunglasses')` `r emo::ji('fire')` ``` <center> 👽 😎 🔥 </center> ```r `r icon_style(fontawesome("rocket", style = "solid"), scale = 2, fill = "red")` ``` <center> <svg viewBox="0 0 512 512" style="position:relative;display:inline-block;top:.1em;fill:red;height:2em;" xmlns="http://www.w3.org/2000/svg"> <path d="M505.12019,19.09375c-1.18945-5.53125-6.65819-11-12.207-12.1875C460.716,0,435.507,0,410.40747,0,307.17523,0,245.26909,55.20312,199.05238,128H94.83772c-16.34763.01562-35.55658,11.875-42.88664,26.48438L2.51562,253.29688A28.4,28.4,0,0,0,0,264a24.00867,24.00867,0,0,0,24.00582,24H127.81618l-22.47457,22.46875c-11.36521,11.36133-12.99607,32.25781,0,45.25L156.24582,406.625c11.15623,11.1875,32.15619,13.15625,45.27726,0l22.47457-22.46875V488a24.00867,24.00867,0,0,0,24.00581,24,28.55934,28.55934,0,0,0,10.707-2.51562l98.72834-49.39063c14.62888-7.29687,26.50776-26.5,26.50776-42.85937V312.79688c72.59753-46.3125,128.03493-108.40626,128.03493-211.09376C512.07526,76.5,512.07526,51.29688,505.12019,19.09375ZM384.04033,168A40,40,0,1,1,424.05,128,40.02322,40.02322,0,0,1,384.04033,168Z"></path></svg> </center> For more info see [the `emo` GitHub repo](https://github.com/hadley/emo) and [the `icons` GitHub repo](https://github.com/mitchelloharawild/icons). --- # The `RMarkdown playground` web app <iframe src="https://dal-unige.shinyapps.io/rmd_app/" width="100%" height="450px" data-external="1"></iframe> Find the app [here](https://dal-unige.shinyapps.io/rmd_app/). --- class: inverse, center, middle # Your turn! (Group exercise) .center[In group, try to compile a `.Rmd` document with a title, author, date, compiled `R` code, and a statistical graph (e.g. boxplot, histogram, barplots, etc) of your choice. You can also try to add other elements discussed (tables, images, etc). Show it to the audience if interested!] .center[Also, try to reproduce this equation in your document: `$$s^{2}=\frac{\sum_{i=1}^{n}\left(x_{i}-\bar{x}\right)^{2}}{n-1}$$`] Hint: Use `\(\LaTeX\)` commands `^`,`_`, `\sum{}`, `\frac{}{}` and `\bar{}`. You can also use the web app presented before for reference. --- class: inverse, center, middle # Tools for Scientific reporting --- # `xaringan` for scientific slideshows `xaringan` is an R package for creating scientific slideshows with [`remark.js`](https://remarkjs.com) through `RMarkdown`. `xaringan` provide the ability to easily include a large number of elements (text, images, code, `\(\LaTeX\)` equations, videos, `html` elements) and offer the possibility of complex customization with `css` and `javascript`. .center[![:scale 20%](data:image/png;base64,#assets/xaringan.png)] Find more informations on the [`xaringan` wiki](https://github.com/yihui/xaringan/wiki) and on the [`xaringan` GitHub repository](https://github.com/yihui/xaringan). --- # Introduction to `xaringan` <div align="center"> <iframe id="xaringan_intro" title="Introduction to xaringan" width="900" height="440" src="https://slides.yihui.org/xaringan/#1"> </iframe> </div> --- # `xaringan` slideshow example <div align="center"> <iframe id="xaringan_ex" title="xarigan slideshows example" width="900" height="440" src="https://raw.githack.com/stephaneguerrier/data_analytics/master/Lecture1.html#1"> </iframe> </div> --- # `xaringan::infinite_moon_reader()` Instant preview without fully rebuilding HTML, and the linked navigation <div align="center"> ![:scale 60%](data:image/png;base64,#assets/gif_inf_m_r.gif) </div> --- # GitHub for collaborative writing/programming <svg viewBox="0 0 496 512" style="height:1em;position:relative;display:inline-block;top:.1em;" xmlns="http://www.w3.org/2000/svg"> <path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"></path></svg> [GitHub](https://github.com/) is a platform which enables sharing and collaboration for software development. It provides a version control system using `Git`. <div align="center"> ![:scale 40%](data:image/png;base64,#assets/github.png) </div> .content-box-blue[ Create an account on [GitHub](https://github.com/) and install [GitHub desktop](https://desktop.github.com/). You can then follow this [serie](https://www.youtube.com/watch?v=XBzUqQbHHhw) of three videos that presents a detailled step-by-step introduction to using GitHub with Github Desktop. You can also read [this introduction to GitHub](https://docs.github.com/en/desktop/installing-and-configuring-github-desktop/creating-your-first-repository-using-github-desktop). ] --- # Mathpix to easily insert math equation in `\(\LaTeX\)` <blockquote> Mathpix Snip digitizes handwritten or printed text, and copies outputs to the clipboard that can be pasted into LaTeX editors like Overleaf, Markdown editors like Typora, Microsoft Word, and more. .right[-- <cite>Mathpix Snip</cite>] </blockquote> <div align="center"> <iframe width="560" height="315" src="https://www.youtube.com/embed/Pc_6aKPYBwQ" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> </div> Find more informations [here](https://mathpix.com/). --- class: inverse, center, middle # Interactive elements --- # GIF with `iframe` tag .scroll-box-80[ ```r <iframe src="https://giphy.com/embed/l46CsCs3cOTdErUuk" width="480" height="363" frameBorder="0" class="giphy-embed" allowFullScreen></iframe><p><a href="https://giphy.com/gifs/election2016-hillary-clinton-i-believe-in-science-l46CsCs3cOTdErUuk">via GIPHY</a></p> ``` ] <center> <iframe src="https://giphy.com/embed/l46CsCs3cOTdErUuk" width="480" height="263" frameBorder="0" class="giphy-embed" allowFullScreen></iframe><p><a href="https://giphy.com/gifs/election2016-hillary-clinton-i-believe-in-science-l46CsCs3cOTdErUuk">via GIPHY</a></p> </center> --- # HTML widgets ### `plotly` example .scroll-box-20[ ```r rm(list=ls()) library(plotly) library(reshape2) # example from https://stackoverflow.com/questions/38331198/add-regression-plane-to-3d-scatter-plot-in-plotly #load data my_df <- iris petal_lm <- lm(Petal.Length ~ 0 + Sepal.Length + Sepal.Width,data = my_df) # Graph Resolution (more important for more complex shapes) graph_reso <- 0.05 #Setup Axis axis_x <- seq(min(my_df$Sepal.Length), max(my_df$Sepal.Length), by = graph_reso) axis_y <- seq(min(my_df$Sepal.Width), max(my_df$Sepal.Width), by = graph_reso) #Sample points petal_lm_surface <- expand.grid(Sepal.Length = axis_x,Sepal.Width = axis_y,KEEP.OUT.ATTRS = F) petal_lm_surface$Petal.Length <- predict.lm(petal_lm, newdata = petal_lm_surface) petal_lm_surface <- acast(petal_lm_surface, Sepal.Width ~ Sepal.Length, value.var = "Petal.Length") #y ~ x #define color mycol = RColorBrewer::brewer.pal(n = 3, name = "Dark2") hcolors=c(mycol)[my_df$Species] iris_plot <- plot_ly(my_df, x = ~Sepal.Length, y = ~Sepal.Width, z = ~Petal.Length, text = ~Species, # EDIT: ~ added type = "scatter3d", mode = "markers", marker = list(color = hcolors)) iris_plot <- add_trace(p = iris_plot, z = petal_lm_surface, x = axis_x, y = axis_y, type = "surface") iris_plot ``` ] --- # HTML widgets <div align="center">
</div> You can find a gallery of `html widgets` for `R` [here](https://www.htmlwidgets.org/showcase_leaflet.html). --- # Youtube with `iframe` tag Musical break with Koffi Olomidé interpreted by Youssoupha ```r <center> <iframe width="660" height="365" src="https://www.youtube.com/embed/RALtocwIcWI?start=391" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> </center> ``` <center> <iframe width="560" height="315" src="https://www.youtube.com/embed/RALtocwIcWI?start=391" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> </center> --- class: inverse, center, middle # Advanced customization options --- # Customization and templates for `.pdf` compilation When compiling a `.Rmd` document to a `.pdf` format, you specify customization by specifying `\(\LaTeX\)` and `pandoc` options. When you compile a `.Rmd` document to a `.pdf`, you specify `CSS` and `HTML` options. You can find further details about customization of `.pdf` compiled-report [here](https://bookdown.org/yihui/rmarkdown/pdf-document.html). If you want to use `RMarkdown` for your semester project and want to consider customizing the default `.pdf` compilation options, we suggest that you consider using the package `stevetemplates` that provides some template for `RMarkdown` academic report compiled in `.pdf`. To do so, install the package from `CRAN`: ```r install.packages("stevetemplates") ``` In `RStudio` you can then go to `File` > `New File` > `R Markdown` and select any template you’d like to use. --- # Templates for `.pdf` compilation of a `.Rmd` ### Opening a new `.Rmd` document based on a template .center[![:scale 75%](data:image/png;base64,#assets/gif_template_pdf.gif)] --- # Themes for `.html` compilation of a `.Rmd` You can specify themes with the `YAML` option `theme`. `RMarkdown` provide built-in themes but many themes are accessible by using external packages available on `CRAN` or on GitHub. Two packages offer several templates: - `prettydoc` by Yixuan Qiu - `rmdformats` by Julien Barnier ```r --- title: Scientific Reporting author: Lionel Voirol date: "`r format(Sys.time(), '%d %B, %Y')`" output: html_document: css: "my_style.css" toc: true * theme: united bibliography: biblio.bib --- ``` --- # Themes for `.html` compilation of a `.Rmd` Find a non exhaustive gallery of available themes [here](https://www.datadreaming.org/post/r-markdown-theme-gallery/). .pull-left[ .center[![:scale 50%](data:image/png;base64,#assets/theme_1.png)] ] .pull-right[ .center[![:scale 70%](data:image/png;base64,#assets/theme_2.png)] ] --- # Themes for `xaringan` presentations The excellent [`xaringanthemer R` package](https://pkg.garrickadenbuie.com/xaringanthemer/index.html) provides the ability to easily customize your `xaringan` presentation and proposes various built-in themes. .center[![:scale 50%](data:image/png;base64,#assets/theme_xar_1.png)] .center[![:scale 50%](data:image/png;base64,#assets/theme_xar_2.png)] --- # Custom `CSS` for `.html` compilation ### Centered header ```css h1, h2, h3 { text-align: center; } ``` ### Change color of hyperlinks ```css a { color: dodgerblue; } ``` etc... --- # `HTML` and `CSS` inline elements for `.html` compilation ```r <button data-toggle="collapse" data-target="#demo"> More info </button> <div id="demo" class="collapse"> <p>Some additional info… :)</p> </div> ``` .center[![:scale 30%](data:image/png;base64,#assets/button_1.gif)] ```r <div class="alert alert-success"> <p><strong>Some important Info:</strong> something</p> ``` .center[![:scale 100%](data:image/png;base64,#assets/colorbox.png)] --- class: inverse, center, middle # Your turn! (individual exercise) .center[![:scale 15%](data:image/png;base64,#assets/logo-tinytex.png)] Install [`tinytex`](https://yihui.org/tinytex/) `\(\LaTeX\)` distribution and try to compile the default `.Rmd` template to a `.pdf` document from `RStudio`. ```r install.packages('tinytex') tinytex::install_tinytex() ``` --- # References - [RMarkdown (RStudio)](https://rmarkdown.rstudio.com/) - [Rstudio cheatsheet](https://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf) - [RMarkdown: The Definitive Guide](https://bookdown.org/yihui/rmarkdown/) - [RMarkdown Cookbook](https://bookdown.org/yihui/rmarkdown-cookbook/) - [R for Data Science, chapter on RMarkdown](https://r4ds.had.co.nz/r-markdown.html) - [An Introduction to Statistical Programming Methods with R, chapter on RMarkdown](https://smac-group.github.io/ds/section-rmarkdown.html) - [Pimp my RMD: a few tips for RMarkdown](https://holtzy.github.io/Pimp-my-rmd/) - [Rmarkdown templates for PDF compilation](https://github.com/svmiller/stevetemplates) - [Xaringan GitHub repo](https://github.com/yihui/xaringan) - [Sharing Your Work with xaringan](https://spcanelon.github.io/xaringan-basics-and-beyond/) --- class: sydney-blue, center, middle background-size: 260px background-position: 5% 95% # Thank you ### Any questions? .pull-down[ <a href="https://lionelvoirol.github.io/workshop_scientific_reporting/#1"> .white[<svg viewBox="0 0 576 512" style="height:1em;position:relative;display:inline-block;top:.1em;" xmlns="http://www.w3.org/2000/svg"> <path d="M480 416v16c0 26.51-21.49 48-48 48H48c-26.51 0-48-21.49-48-48V176c0-26.51 21.49-48 48-48h16v48H54a6 6 0 0 0-6 6v244a6 6 0 0 0 6 6h372a6 6 0 0 0 6-6v-10h48zm42-336H150a6 6 0 0 0-6 6v244a6 6 0 0 0 6 6h372a6 6 0 0 0 6-6V86a6 6 0 0 0-6-6zm6-48c26.51 0 48 21.49 48 48v256c0 26.51-21.49 48-48 48H144c-26.51 0-48-21.49-48-48V80c0-26.51 21.49-48 48-48h384zM264 144c0 22.091-17.909 40-40 40s-40-17.909-40-40 17.909-40 40-40 40 17.909 40 40zm-72 96l39.515-39.515c4.686-4.686 12.284-4.686 16.971 0L288 240l103.515-103.515c4.686-4.686 12.284-4.686 16.971 0L480 208v80H192v-48z"></path></svg> slides ] </a> <a href="mailto:lionel.voirol@unige.ch"> .white[<svg viewBox="0 0 512 512" style="height:1em;position:relative;display:inline-block;top:.1em;" xmlns="http://www.w3.org/2000/svg"> <path d="M440 6.5L24 246.4c-34.4 19.9-31.1 70.8 5.7 85.9L144 379.6V464c0 46.4 59.2 65.5 86.6 28.6l43.8-59.1 111.9 46.2c5.9 2.4 12.1 3.6 18.3 3.6 8.2 0 16.3-2.1 23.6-6.2 12.8-7.2 21.6-20 23.9-34.5l59.4-387.2c6.1-40.1-36.9-68.8-71.5-48.9zM192 464v-64.6l36.6 15.1L192 464zm212.6-28.7l-153.8-63.5L391 169.5c10.7-15.5-9.5-33.5-23.7-21.2L155.8 332.6 48 288 464 48l-59.4 387.3z"></path></svg> Lionel.Voirol@unige.ch] </a> <a href="https://github.com/lionelvoirol"> .white[<svg viewBox="0 0 496 512" style="height:1em;position:relative;display:inline-block;top:.1em;" xmlns="http://www.w3.org/2000/svg"> <path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"></path></svg> @lionelvoirol] </a> <br><br><br> ]