---
title: "Quality Report: ring width measurement"

date: "`r Sys.Date()`"
output:
  html_document:
  theme: flatly
highlight: tango

params:
  robj: NULL


---
```{r setup_scale, include=FALSE}
# This chunk sets global options to hide all R code from appearing in the output
if (!requireNamespace("htmltools", quietly = TRUE)) {
  stop("Package 'htmltools' is required to run this function. Please install it.")
}
knitr::opts_chunk$set(echo = FALSE)
robj <- params$robj
```

<br>
<br>

This report compares the median ring-width of the target site(s) with the <b><u>`r robj[[1]]$scale.parms["scale.N_nbs"] `</u> </b> nearest neighbors in the dataset <b><u>`r  robj[[1]]$scale.parms["scale.label_data_ref"] `</u> </b>, using a maximum search distance of <b><u>`r robj[[1]]$scale.parms["scale.max_dist_km"] ` </u> </b>  km.

<br>


```{r  results='asis', warning=FALSE, message=FALSE, fig.width=10, fig.height=5, fig.align='left'}
library(data.table)
library(growthTrendR)
library(gt)

library(stringr)
library(patchwork)
library(ggplot2)


for (i in seq_along(robj)) {
  
  # Generate plots for this scale object
  plt.lst <- plot_scale(robj[[i]])
  
  # Combine the year and lat-long plots side-by-side
  p.i <- (plt.lst$plot.year | plt.lst$plot.ll) +
    plot_annotation(
      title = paste0(
    "Species: ", sub("_.*", "", names(robj)[[i]]), "\n",
    "Site: ", sub(".*_", "", names(robj)[[i]])
  ),
      caption = paste0("Data source: ", robj[[i]]$scale.parms["scale.label_data_ref"]),
      tag_levels = 'a',
      tag_suffix = ")"
    ) &
    theme(
      plot.title = element_text(face = "bold"),
      plot.tag = element_text(face = "bold"),
      plot.caption = element_text(hjust = 0.2, face = "italic")
    )
  
  print(p.i)
}

```

