-
Notifications
You must be signed in to change notification settings - Fork 0
/
SBF_comparison_version.Rmd
145 lines (110 loc) · 5.29 KB
/
SBF_comparison_version.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
---
title: "Etude SBF"
output:
html_document: default
word_document: default
date: '2022-03-23'
params:
working_directory: "~/Documents/Tunaatlas_level1/jobs/20220428104014"
---
This document give a quick analysis of different way to handle the treatment of the Southern Bluefin Tuna in the Global Tuna Atlas.
It explains how it was done before and how we propose it to be done now, showing the differences and remains open to modification/proposition.
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = FALSE,
message = TRUE,
warning = TRUE
)
library(readtext)
library(flextable)
set_flextable_defaults(
font.size = 30,
font.color = "black",
table.layout = "fixed",
digits = NULL,
theme_fun = "theme_box"
)
options(scipen=999)
library(dplyr)
library(stringr)
library(readr)
library(webshot)
if(require("htmltools"))
div(flextable_html_dependency())
```
```{r}
mapping_codelist <- readRDS("data/mapping_codelist.rds")
initial_SBF <- mapping_codelist%>% filter(species == "SBF")
```
# Current version
For now, what is done is remove all the SBF catches (in tons and numbers) coming from a source authority different than CCSBT.
```{r}
#Paul treatment
Actual <- initial_SBF[ which(!(initial_SBF$species %in% "SBF" & initial_SBF$source_authority %in% c("ICCAT","IOTC","IATTC","WCPFC"))), ]%>% filter(species == "SBF")
```
# Issue with this method
For some years, or gears, the availibility of SBF catches is only coming from CTOI or ICCAT.
```{r}
# My treatment
source("https://raw.githubusercontent.com/BastienIRD/Tunaatlas_level1/main/fonction_overlap.R")
georef_dataset <- function_overlapped(dataset = initial_SBF, con =con, rfmo_to_keep = "CCSBT",
rfmo_not_to_keep = "IOTC",
strata =c( "species", "time_start", "time_end", "unit"))
georef_dataset <- function_overlapped(dataset = georef_dataset, con =con, rfmo_to_keep = "CCSBT",
rfmo_not_to_keep = "CCSBT",
strata =c( "species", "time_start", "time_end",
"unit"))
Proposition <- georef_dataset %>% filter(species == "SBF")
```
```{r}
comp <- gdata::combine(initial_SBF, Actual, Proposition)
comp$unit <- str_replace(comp$unit, "MTNO","MT")
comp$unit <- str_replace(comp$unit, "NOMT","NO")
comp <- comp%>% group_by(source, time_start, unit) %>% summarise(Value = sum(value)) %>% mutate(time_start = as.Date(time_start))
```
```{r}
library(lubridate)
comp_year <- comp %>% mutate(Year =lubridate::year(time_start)) %>%ungroup() %>% group_by(Year, unit, source) %>% summarise(Value = sum(Value))
```
```{r}
library(ggplot2)
ggplot(comp_year)+
aes(x = Year, y = Value, colour = source) +
geom_line(size = 0.5) +
scale_color_hue(direction = 1) +
theme_minimal() +
facet_wrap(vars(unit), scales = "free_y")
```
The difference between the two dataset is `r sum((Actual %>% filter(unit == "MT"))$value) - sum((Proposition %>% filter(unit == "MT"))$value)` in tons and `r sum((Actual %>% filter(unit == "NO"))$value) - sum((Proposition %>% filter(unit == "NO"))$value)` in number of fish.
# Other proposition
We could also decide to keep the data from other rfmo's if there is no equivalent in year, area.
The results would be the following :
```{r}
# My treatment
source("https://raw.githubusercontent.com/BastienIRD/Tunaatlas_level1/main/fonction_overlap.R")
georef_dataset <- function_overlapped(dataset = mapping_codelist, con =con, rfmo_to_keep = "CCSBT",
rfmo_not_to_keep = "IOTC",
strata =c("geographic_identifier", "species", "time_start", "time_end", "unit"))
georef_dataset <- function_overlapped(dataset = georef_dataset, con =con, rfmo_to_keep = "CCSBT",
rfmo_not_to_keep = "CCSBT",
strata =c("geographic_identifier", "species", "time_start", "time_end",
"unit"))
Proposition <- georef_dataset %>% filter(species == "SBF")
```
```{r}
comp <- gdata::combine(initial_SBF, Actual, Proposition)
comp$unit <- str_replace(comp$unit, "MTNO","MT")
comp$unit <- str_replace(comp$unit, "NOMT","NO")
comp <- comp%>% group_by(source, time_start, unit) %>% summarise(Value = sum(value)) %>% mutate(time_start = as.Date(time_start))
```
```{r}
comp_year <- comp %>% mutate(Year =lubridate::year(time_start)) %>%ungroup() %>% group_by(Year, unit, source) %>% summarise(Value = sum(Value))
ggplot(comp_year)+
aes(x = Year, y = Value, colour = source) +
geom_line(size = 0.5) +
scale_color_hue(direction = 1) +
theme_minimal() +
facet_wrap(vars(unit), scales = "free_y")
```
The difference between the two dataset is `r sum((Actual %>% filter(unit == "MT"))$value) - sum((Proposition %>% filter(unit == "MT"))$value)` in tons and `r sum((Actual %>% filter(unit == "NO"))$value) - sum((Proposition %>% filter(unit == "NO"))$value)` in number of fish.
For more advanced comparison between the two dataset, please check: