---
title: "Dataset QA summary"
output: html_document
params:
  data: ""
---

```{r setup, include=FALSE}
library(spant)
library(ggplot2)
knitr::opts_chunk$set(echo = FALSE)
theme_set(theme_bw())
```

## Summary metrics

### Dynamic frequency shifts range
```{r, fig.width=10}
ggplot(params$data$summary, aes(x = shift_hz_range, y = labels)) + geom_col() + 
      ylab("") + xlab("Shift range (Hz)") + scale_y_discrete(limits = rev)
```

### Smoothed dynamic linewidths range
```{r, fig.width=10, warning = FALSE, message = FALSE}
ggplot(params$data$summary, aes(x = lw_ppm_smo_range, y = labels)) + 
  geom_col() + ylab("") + xlab("Smoothed linewidth range (ppm)") +
  scale_y_discrete(limits = rev)
```

### Median single shot SNR
```{r, fig.width=10}
ggplot(params$data$summary, aes(x = ss_median_spec_snr, y = labels)) + 
  geom_col() + ylab("") + xlab("Median single shot SNR") +
  scale_y_discrete(limits = rev)
```

### Dynamic mean corrected spectral linewidths
```{r, fig.width=10}
ggplot(params$data$summary, aes(x = mean_corr_spec_lw, y = labels)) +
  geom_col() + ylab("") + xlab("Linewidth for mean corrected data (ppm)") +
  scale_y_discrete(limits = rev)
```

### Dynamic lipid fluctuation range
```{r, fig.width=10}
ggplot(params$data$summary, aes(x = dlfr * 100, y = labels)) +
  geom_col() + ylab("") + 
  xlab("Dynamic lipid fluctuation range (% tCr intensity)") +
  scale_y_discrete(limits = rev)
```

### Dynamic fluctuation range
```{r, fig.width=10}
ggplot(params$data$summary, aes(x = dfr * 100, y = labels)) +
  geom_col() + ylab("") + xlab("Dynamic fluctuation range (% tCr intensity)") +
  scale_y_discrete(limits = rev)
```

### Dataset quality summary

Dataset mean single shot SNR : `r round(mean(params$data$summary$ss_median_spec_snr), 1)`

Dataset standard deviation single shot SNR : `r round(sd(params$data$summary$ss_median_spec_snr), 1)`

Dataset mean spectral linewidth : `r round(mean(params$data$summary$mean_corr_spec_lw), 3)`

Dataset standard deviation spectral linewidth : `r round(sd(params$data$summary$mean_corr_spec_lw), 3)`

```{r results='asis'}
if (!is.null(params$data$exclude_labels)) {
  cat("### Excluded scan labels\n")
  for (x in params$data$exclude_labels) cat("- ", x, "\n")
}
```