---
title: "Figure S5 Difference compared to another plant and time-series"
author: "Mads Albertsen"
date: "`r format(Sys.time(), '%d-%m-%Y')`"
output: html_document
---

## Load packages
```{r Load_packages, message=FALSE, warning=FALSE, results='hide'}
library("ampvis")
```

## Load data
```{r load_data}
data(DNAext_1.0)
```

# Subset to the relevant samples
```{r storage_time_subset, message=FALSE}
bb_time_plant <- subset_samples(V13, Exp.beadbeating == "YES" | (Exp.time == "YES" & Date != "2012-10-31") | Plant == "AAE") %>%
  rarefy_even_depth(sample.size = 25000, rngseed = 712) %>%
  filter_taxa(function(x) max(x) > 10, TRUE)
```

## Figure S5: Difference compared to another plant and time-series
```{r beta_time}
beta_time <- amp_test_cluster(data = bb_time_plant, 
                              group = "Beadbeating", 
                              method = "bray", 
                              plot.color = "Date", 
                              plot.label = c("Beadbeating", "Plant"),
                              plot.theme = "clean")
```

The clustering supports the conclusion that varience from different bead beating settings is larger than the varience by sampling 5 months appart. While still enables clustering of samples within the same wastewater treatment plant.
```{r beta_time_plot, fig.align='center', fig.height=5, fig.width=6, message=FALSE}
beta_time$plot_cluster +
  scale_color_discrete(name = "Sampling date") +
  theme(legend.key.width = unit(3, "mm"),
        legend.key.height = unit(3, "mm"),
        legend.key = element_blank(),
        legend.text = element_text(size = 10),
        legend.title = element_text(size = 10),
        legend.position = c(0.89,0.89))
```

```{r save_S5, eval=FALSE}
ggsave("plots/S5_Fig.eps", width = 140, height = 120, units = "mm")
```