---
title: "Figure 3B BB Ordinate"
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 bead-beating related samples and rarefy
```{r BB_subset1, message=FALSE}
bb_time <- subset_samples(V13, Exp.beadbeating == "YES" | (Exp.time == "YES" & Date != "2012-10-31")) %>% 
  rarefy_even_depth(sample.size = 25000, rngseed = 712) %>%
  filter_taxa(function(x) max(x) >= 10, TRUE)
```

## Figure 3B: Bead beating compared with time
```{r Fig1B, fig.width=4, fig.height=2.8, fig.align='center'}
amp_ordinate(data = bb_time, 
             plot.color.order = c("20s4ms","20s6ms","80s4ms","40s6ms","80s6ms","160s6ms","400s6ms"),
             plot.color = "Beadbeating", 
             plot.point.size = 2,
             plot.theme = "clean",
             plot.shape = "Date"
             ) +
  scale_shape_discrete(name = "Sampling date", 
                       labels=c("12-10-17","12-10-31","12-11-14", 
                                "12-12-12","13-01-16","13-03-25")) +
  scale_color_discrete(name = "Bead beating", 
                       labels=c("  20s at 4m/s","  20s at 6m/s","  80s at 4m/s",
                                "  40s at 6m/s","  80s at 6m/s","160s at 6m/s","400s at 6m/s")) +  
  theme(axis.text = element_blank(),
        legend.key.height = unit(3, "mm"),
        legend.key = element_blank()
        )
```

## Save the plot
```{r save, eval=FALSE}
ggsave("plots/Fig1B.eps", width = 95, height = 70, units = "mm")
```