---
title: "NSW seagarfish stock assessment data"
author: "Marco Kienzle"
date: "`r Sys.Date()`"
output:
flexdashboard::flex_dashboard:
orientation: columns
social: menu
source_code: embed
---
```{r setup, include=FALSE}
library(ggplot2)
library(plotly)
library(plyr)
library(flexdashboard)
```
5 types of data are used to assess this stock
=======================================================================
Column {data-width=800} {.tabset}
-----------------------------------------------------------------------
### Age distributions of seagarfish caught by the fishery
```{r}
library(RColorBrewer)
# Age data were rounded
nb.at.age.tmp <- round(read.csv("../Data/GarfishAgeData.csv", row.names = 1, colClasses = c("character", rep("numeric",6))))
dimnames(nb.at.age.tmp)[[2]] <- seq(0,ncol(nb.at.age.tmp) - 1)
library(tidyverse)
nb.at.age.long = rownames_to_column(nb.at.age.tmp, var = "year") %>% as_tibble() %>% gather(key = "age", value = "nb of fish", `0`, `1`,`2`, `3`, `4`, `5`)
nb.at.age.long$Cohort = as.numeric(substr(nb.at.age.long$year,1,4)) - as.numeric(nb.at.age.long$age)
nb.at.age.long$Cohort = as.factor(nb.at.age.long$Cohort - min(nb.at.age.long$Cohort) + 1)
p = ggplot(nb.at.age.long, aes(x = age, y = `nb of fish`, fill = Cohort)) +
geom_col(width=.75) +
facet_wrap( ~ year) +
scale_fill_manual(values=rep(brewer.pal(9,"Set1"),times=7)) +
theme(legend.position = "none",
plot.margin = unit(c(t=0.5,r=0.2,b=0.8,l=0.8), "cm"),
strip.text.x = element_text(margin = margin(t = 0.1, r = 0,b = 0, l= 0, "cm"))) +
xlab("Age group") + ylab("Number of fish aged")
ggplotly(p)
```
### Weight at age
```{r}
weight.at.age <- read.csv("../Data/GarfishWeightAtAge.csv", row.names = 1)
dimnames(weight.at.age)[[2]] <- seq(0,ncol(nb.at.age.tmp) - 1)
library(tidyverse)
weight.at.age.long = rownames_to_column(weight.at.age, var = "year") %>% as_tibble() %>% gather(key = "age", value = "Weight", `0`, `1`,`2`, `3`, `4`, `5`)
p = ggplot(weight.at.age.long, aes(x = age, y = Weight, group = 1)) +
geom_point() + geom_line(col = "#F8766D", size = 1) +
facet_wrap( ~ year) + xlab("Age-group") + ylab("Mean weight (kg)") +
theme(plot.margin = unit(c(t=0.5,r=0.2,b=0.8,l=1.0), "cm"), strip.text.x = element_text(margin = margin(t = 0.1, r = 0,b = 0, l= 0, "cm")))
ggplotly(p)
```
Column {.tabset}
-----------------------------------------------------------------------
### Catch time series
```{r}
catch <- read.csv("../Data/GarfishCatchData.csv")
p <- ggplot(catch, aes(x=Year, y=Catch.in.kg * 1e-3)) +
geom_bar(stat="identity", fill = "#00BFC4") + xlab("") + ylab("Catch (t)") +
#scale_x_discrete(guide = guide_axis(check.overlap = TRUE))
#scale_x_discrete(guide = guide_axis(n.dodge=2))
scale_x_discrete(limits=catch$Year,breaks=catch$Year[seq(1,length(catch$Year),by=2)])
ggplotly(p)
```
### Effort time series
```{r}
effort <- read.csv("../Data/GarfishEffortData.csv")
p <- ggplot(effort, aes(x=Year, y=Effort.in.days, group = 1)) +
geom_line(col = "#00BFC4", size = 1) +
geom_point() +
xlab("") + ylab("Effort (in fishing days)") +
ylim(0, max(effort$Effort.in.days * 1.1)) +
#scale_x_discrete(guide = guide_axis(check.overlap = TRUE))
#scale_x_discrete(guide = guide_axis(n.dodge=2))
scale_x_discrete(limits=effort$Year,breaks=effort$Year[seq(1,length(effort$Year),by=2)])
ggplotly(p)
```
### Mesh size time series
```{r}
effort <- read.csv("../Data/GarfishEffortData.csv")
effort$mesh.size = ifelse(as.numeric(substr(effort$Year,1,4)) < 2009, 25, 28)
p <- ggplot(effort, aes(x=Year, y=mesh.size)) +
#geom_line(col = "#00BFC4", size = 1) +
geom_point() +
xlab("") + ylab("Mesh size (mm)") +
#ylim(0, max(effort$Effort.in.days * 1.1)) +
#scale_x_discrete(guide = guide_axis(check.overlap = TRUE))
#scale_x_discrete(guide = guide_axis(n.dodge=2)) + guides(x = guide_axis(angle = 45))
scale_x_discrete(limits=effort$Year,breaks=effort$Year[seq(1,length(effort$Year),by=2)])
ggplotly(p)
```