---
title: "Rticles: scientific documents with bookdown"
subtitle: "www.lozanoisla.com"
author:
  - "Flavio Lozano-Isla $^{1*}$"
  - "$^{1}$ Agronomist MSc, email: flozano@lamolina.edu.pe"
date: "`r if (knitr:::is_html_output()) format(Sys.time(), '%Y-%m-%d  %H:%M')`"
description: document template for scientific documents
favicon: https://inkaverse.com/img/inkaverse.png
github-repo: flavjack/rticles
site: bookdown::bookdown_site
documentclass: book
bookdown::gitbook:
output: 
  bookdown::html_document2:
    toc: true
    toc_float: true
    global_numbering: TRUE
  bookdown::word_document2:
    reference_docx: files/style.docx
    global_numbering: TRUE
always_allow_html: true
link-citations: true
colorlinks: true
zotero: true
bibliography: [files/book.bib, files/pkgs.bib]
csl: https://www.zotero.org/styles/apa
editor_options: 
  chunk_output_type: console
---

```{r setup, include=FALSE}
source("http://inkaverse.com/rticles.r")
```

```{r}
url <- paste0("https://docs.google.com/spreadsheets/d/"
              , "15r7ZwcZZHbEgltlF6gSFvCTFA-CFzVBWwg3mFlRyKPs/edit#gid=172957346") 

# browseURL(url)

fb <- url %>% 
  gsheet2tbl() %>% 
  rename_with(tolower) %>% 
  mutate(across(c(treat, geno, bloque), ~ as.factor(.))) %>% 
  mutate(across(where(is.factor), ~ gsub("[[:space:]]", "", .)) ) %>% 
  as.data.frame()
# str(fb)
```

# Abstract {-}

Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. *Nulla facilisi* Ut fringilla. **Suspendisse potenti** Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam.

**KeyWords:** Lorem, ipsum, dolor, sit amet, consectetur.

\newpage

# Introduction

Lorem ipsum [@abbai2019] dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc [@bergström2020; @bhatt2019].

Curabitur tortor [@donald1976] Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrice. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna.

# Materials and Methods

The data was analyzed in the statistical software R [@R-base]. The germination analysis and graphics was carried out with the package GerminaR [@R-bookdown]. Each variable was submitted at analysis of variance (ANOVA) and the mean comparison test used was Student-Newman Keuls (P\<0.05) [@R-citr]. For the multivariate analysis, the principal components analysis (PCA) and cluster hierarchical classification analysis (HCPC) will be used .

The vertical bars represent the means (±SE). The mean differences between the groups are represented by different capital letters and into the group different lowercase letters (SNK, p = 0.05) [@R-ggplot2].

More information about multivarite analysis in <http://factominer.free.fr/index.html>. Explanation for intepretation and analysis:

**PCA:** <https://www.youtube.com/watch?v=pks8m2ka7Pk&feature=youtu.be>

**HCPC:** <https://www.youtube.com/watch?v=4XrgWmN9erg>

## Data set

The data set used for this analysis is available in the following link: [DATA SET](https://docs.google.com/spreadsheets/d/15r7ZwcZZHbEgltlF6gSFvCTFA-CFzVBWwg3mFlRyKPs/edit#gid=1263018298)

## Nulla metus metus

Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante (Table \@ref(tab:table)).

# Results

## Sed convallis tristique sem

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos $g=\left(\frac{\sum_{i=1}^kn_1}{N}\right)100$.

Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet Mauris ipsum .

```{r code, echo=TRUE, eval=FALSE}
library(GerminaR) 

# load data
fb <- prosopis %>% 
  mutate(across(c(rep, nacl, temp), ~ as.character(.) ))

# germination analysis
gsm <- ger_summary(SeedN = "seeds", evalName = "D", data = fb)
str(gsm)

# analisys of variance
av <- aov(formula = grp ~ nacl*temp + rep, data = gsm)
summary(av)

# mean comparision test
mc <- ger_testcomp(aov = av, comp = c("temp", "nacl"), type = "snk")
```

## Class aptent taciti

Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices (Figure \@ref(fig:image)).

# Discussion

Curabitur tortor [@R-knitr], Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante (Figure \@ref(fig:gridplot)).

Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor .

# Conclusions

Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet.

# Acknowledgments

Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi.

# References

::: {#refs}
:::

```{r references}
write_bib(c(.packages()),'files/pkgs.bib')
```

<!-- Tables -->

\newpage

`r if (knitr:::is_html_output()) '# Tables {-}'`

```{r table}
fb %>% 
  select(treat, geno,	bloque, leafdw:lfa) %>% 
  head(10) %>% 
  include_table(
    caption = "Water use effiency dataset import from a googlesheet"
    , notes = "@R-inti"
    , label = "__Source:__"
    )
```

\newpage

```{r webtab}
fb %>% 
  web_table(caption = "Water use effiency dataset to download in html", )
```

\newpage

<!-- Figures -->

`r if (knitr:::is_html_output()) '# Figures {-}'`

```{r gridplot, fig.cap= fig$caption}

#> Plot raw data

wue <- fb %>% 
  plot_raw(type = "boxplot"
           , x = "geno"
           , y = "wue"
           , group = "treat"
           , xlab = "Genotipos"
           , ylab = "Water use efficiency (g/l)"
           , ylimits = c(5, 30, 5)
           , glab = "Tratamientos"
           )


hi <- fb %>% 
  plot_raw(type = "scatterplot"
           , x = "hi"
           , y = "twue"
           , group = "treat"
           , xlab = "Harvest Index"
           , ylab = "Tuber water use efficiency (g/l)"
           , glab = "Tratamientos"
           )

#> Plot summary data

model <- fb %>% 
  yupana_analysis(response = "lfa"
                  , model_factors = "geno*treat"
                  , comparison = c("geno", "treat")
                  )

lfa <- model$meancomp %>% 
  plot_smr(type = "bar"
           , x = "geno"
           , y = "lfa"
           , group = "treat"
           , ylimits = c(0, 12000, 2000)
           , sig = "sig"
           , error = "ste"
           , xlab = "Genotipos"
           , ylab = "Area foliar (cm^2)"
           , color = F
           )

model <- fb %>% 
  yupana_analysis(response = "twue"
                  , model_factors = "geno*treat"
                  , comparison = c("geno", "treat")
                  )

twue <- model$meancomp %>% 
  plot_smr(type = "line"
           , x = "geno"
           , y = "twue"
           , group = "treat"
           , ylimits = c(0, 10, 2)
           , error = "ste"
           , color = c("blue", "red")
           ) +
  labs(x = "Genotipos"
       , y = "Tuber water use effiency (g/l)"
       )

#> Plot figures

grid <- plot_grid(wue, hi, lfa, twue
                  , nrow = 2
                  , labels = "AUTO")

ggsave2("files/fig-01.png"
        , plot = grid
        , dpi= 600
        , width = 20
        , height = 12
        , scale = 1.5
        , units = "cm")

fig <- include_figure(
  figure = "files/fig-01.png"
  , caption = "Water use effiency in 15 potato genotypes"
  , notes = "
  A) Box plot.
  B) Scatter plot
  C) Bar plot
  D) Line plot
  "
  , label = "__Where:__"
  )
fig$figure
```

\newpage

```{r image, fig.cap= fig$caption, out.width= "60%"}

fg <- image_read("https://raw.githubusercontent.com/Flavjack/rticles/master/files/fig_jc.jpg") %>% 
  grid::rasterGrob()

plot <- fg %>% 
  plot_grid() +
  draw_plot_label(
    label = c("A", "B", "C")
    , x = c(0.02, 0.51, 0.02)
    , y = c(0.98, 0.98, 0.30)
    )
  
ggsave2("files/fig-02.png"
        , plot = plot
        , dpi= 300
        , width = 11
        , height = 9
        , units = "cm")

fig <- include_figure(
  figure = "files/fig-02.png"
  , caption = "Plant of *Jatropha curcas*. 
  A) Foliage.
  B) Leaf. 
  C) Fruit."
  )

fig$figure
```

\newpage

```{r mv, fig.cap= fig$caption}
library(FactoMineR)

#> Principal component Analysis

mv <- fb %>% 
  yupana_mvr(last_factor = "bloque"
             , summary_by = c("geno", "treat")
             , groups = "treat"
             )
  
# sink("files/pca.txt")
# # Results
# summary(pca, nbelements = Inf, nb.dec = 2)
# # Correlation de dimensions
# dimdesc(pca)
# sink()

ppi <- 300
png("files/plot_pca_var.png", width=7*ppi, height=7*ppi, res=ppi)

plot.PCA(mv$pca,
         choix="var",
         title="",
         autoLab = "y", 
         cex = 0.8,
         shadowtext = T)

graphics.off()

ppi <- 300
png("files/plot_pca_ind.png", width=7*ppi, height=7*ppi, res=ppi)

plot.PCA(mv$pca,
         choix="ind",
         habillage = 1,
         title="",
         autoLab = "y", 
         cex = 0.8,
         shadowtext = T,
         label = "ind",
         legend = list(bty = "y", x = "topright"))

graphics.off()

# Hierarchical Clustering Analysis

clt <- mv$pca %>% 
  HCPC(., nb.clust=-1, graph = F)

# sink("files/clu.txt")
# clus$call$t$tree
# clus$desc.ind
# clus$desc.var
# sink()

ppi <- 300
png("files/plot_cluster_tree.png", width=7*ppi, height=7*ppi, res=ppi)

plot.HCPC(x = clt, 
          choice = "tree")

graphics.off()

ppi <- 300
png("files/plot_cluster_map.png", width=7*ppi, height=7*ppi, res=ppi)

plot.HCPC(x = clt, choice = "map")

graphics.off()

plot.01 <- image_read("files/plot_pca_var.png") %>% grid::rasterGrob()
plot.02 <- image_read("files/plot_pca_ind.png")  %>% grid::rasterGrob()
plot.03 <- image_read("files/plot_cluster_map.png") %>% grid::rasterGrob()
plot.04 <- image_read("files/plot_cluster_tree.png") %>% grid::rasterGrob()


plot <- plot_grid(plot.01, plot.02, plot.03, plot.04
                  , nrow = 2
                  , labels = "AUTO")

ggsave2("files/fig-03.png"
        , plot = plot
        , dpi = 300
        , width = 13
        , height = 10
        , units = "cm")

fig <- include_figure(
  caption = "Multivariate Analysis: 
  Principal component Analysis and Hierarchical Clustering Analysis."
  , figure = "files/fig-03.png"
  )
  
fig$figure
```

<!-- Anexos -->

`r if (knitr:::is_html_output()) '# Anexos {-}'`

```{r anexo}
if (!file.exists("files/anexo.pdf")){
download.file(
  url = "https://journals.plos.org/ploscompbiol/article/file?id=10.1371/journal.pcbi.1005619&type=printable", destfile = "files/anexo.pdf", mode = "wb")
  }
```

<embed src="files/anexo.pdf" height="600" width="100%" alt="pdf" pluginspage="http://www.adobe.com/products/acrobat/readstep2.html">

```{r appendices, child = 'anexo.Rmd', eval = FALSE}
```

