ohi logo
OHI Science | Citation policy

[REFERENCE RMD FILE: https://cdn.rawgit.com/OHI-Science/ohiprep/master/globalprep/mar/v2016/mar_dataprep.html]

1 Summary

This analysis converts FAO mariculture data into the OHI 2016 global mariculture status score. This also calculates the genetic escapee from mariculture pressure data.

2 Updates from previous assessment

New year of FAO mariculture yield data, but no changes to sustainability or genetic escapee data or general methods. Code has been improved from last year.


3 Data Source

Reference:
http://www.fao.org/fishery/statistics/software/fishstatj/en#downlApp Release date: March 2016 FAO Global Aquaculture Production Quantity 1950_2014

Downloaded: July 29 2016

Description: Quantity (tonnes) of mariculture for each county, species, year.

Time range: 1950-2014


4 Methods

# load libraries, set directories
library(ohicore)  #devtools::install_github('ohi-science/ohicore@dev')
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(stringr)
library(tidyr)

## comment out when knitting
#setwd("globalprep/mar/v2016")


### Load FAO-specific user-defined functions
source('mar_fxs.R') # functions specific to mariculture dealing with compound countries
source('../../../src/R/fao_fxn.R') # function for cleaning FAO files
source('../../../src/R/common.R') # directory locations

5 FAO Mariculuture data

Clean mariculture data: Filter freshwater mariculture, make long format, and clean FAO codes.

mar <- read.csv(file.path(dir_M, 'git-annex/globalprep/_raw_data/FAO_mariculture/d2016/GlobalAquacultureProduction_Quantity_1950_2014.csv'), check.names=FALSE, stringsAsFactors=FALSE) ; head(mar) 
##   Country (Country) Species (ASFIS species)
## 1       Afghanistan           Cyprinids nei
## 2       Afghanistan           Rainbow trout
## 3           Albania             Common carp
## 4           Albania            Crucian carp
## 5           Albania        European seabass
## 6           Albania   Freshwater fishes nei
##   Aquaculture area (FAO major fishing area) Environment (Environment) Unit
## 1                      Asia - Inland waters                Freshwater    t
## 2                      Asia - Inland waters                Freshwater    t
## 3                    Europe - Inland waters                Freshwater    t
## 4                    Europe - Inland waters                Freshwater    t
## 5               Mediterranean and Black Sea                    Marine    t
## 6                    Europe - Inland waters                Freshwater    t
##   1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963
## 1  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...
## 2  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...
## 3  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...
## 4  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...
## 5  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...
## 6  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...
##   1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975  1976  1977
## 1  ...  ...  ...  ...  ... 50 F 50 F 50 F 50 F 50 F 50 F 50 F 150 F 150 F
## 2  ...  ...  ...  ...  ... 10 F 10 F 10 F 10 F 10 F 10 F 10 F  20 F  20 F
## 3  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...   ...   ...
## 4  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...   ...   ...
## 5  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...   ...   ...
## 6  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...  ...   ...   ...
##    1978  1979  1980  1981  1982  1983  1984  1985  1986  1987  1988  1989
## 1 150 F 150 F 150 F 150 F 150 F 150 F 150 F 150 F 150 F 150 F 150 F 150 F
## 2  20 F  20 F  20 F  20 F  20 F  20 F  20 F  20 F  20 F  20 F  20 F  20 F
## 3   ...   ...   ...   ...   4 F  10 F    10    20    48    42    62   126
## 4   ...   ...   ...   1 F   6 F   8 F    10    10    12     5     2     7
## 5   ...   ...   ...   ...   ...   ...   ...   ...   ...   ...   ...   ...
## 6   ...   ...   ...   ...   ...   ...     1     6    30    20    11     1
##    1990  1991  1992  1993  1994  1995  1996  1997  1998  1999  2000  2001
## 1 300 F 300 F 300 F 300 F 300 F 300 F 300 F 300 F 300 F 300 F 300 F 400 F
## 2   ...   ...   ...   ...   ...   ...   ...   ...   ...   ...   ...  50 F
## 3  76 F  23 F  13 F  13 F  14 F  34 F  45 F     4     4     2     2     3
## 4   5 F   2 F   1 F   2 F   1 F     -     -     -     -     -     -     -
## 5   ...   ...   ...   ...   ...   ...   ...   ...   ...   ...   ...   ...
## 6   1 F   1 F   1 F   1 F   0 0   0 0   0 0   0 0   0 0   0 0   0 0   0 0
##    2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013
## 1 400 F 400 F 400 F 400 F 400 F 900 F 900 F 900 F 900 F 900 F 900 F 900 F
## 2  50 F  50 F  50 F  50 F  50 F 150 F 150 F 150 F 150 F 150 F 150 F 150 F
## 3     4     6     8     6    10    10    74     6     6     8   222 200 F
## 4     -     -     -     -     -     -     -     -     -     -     -     -
## 5   ...   ...   ...   ...    87    84   142   135   135   170   170 170 F
## 6   0 0   0 0     -     -     -     -     -     -     -     -     -     -
##    2014
## 1 900 F
## 2 150 F
## 3   214
## 4     -
## 5 129.4
## 6     -
mar <- mar %>%
  rename(country = `Country (Country)`,
         FAO_name = `Species (ASFIS species)`,
         fao = `Aquaculture area (FAO major fishing area)`,
         environment = `Environment (Environment)`)
table(mar$environment)  
## 
##               Brackishwater    Freshwater        Marine 
##             1           475          1688          1014
# include only marine environments
mar <- mar %>%
filter(environment %in% c("Brackishwater", "Marine"))  

## long format and clean FAO codes:
mar <- mar %>%
  select(-Unit) 

mar <- mar %>%
  gather("year", "value", 5:(ncol(mar))) %>%
    fao_clean_data() 

Update species names and exclude non-food species.

mar_sp <- read.csv('raw/species_list.csv', stringsAsFactors=FALSE) %>%
  select(FAO_name, species, exclude, alias, Taxon_code)
new.spp <- setdiff(mar$FAO_name, mar_sp$FAO_name)
new.spp # check: if dim has 0 rows it means all match
## character(0)
# if length(new.spp) >0 , hand check whether to keep (exclude seaweeds and species harvested for ornamental/medicinal), check if synonyms match Trujillo names

# Remove species not relevant to mariculuture goal (i.e., non-food species)
mar <- left_join (mar, mar_sp, by="FAO_name") 
mar <- filter (mar, exclude==0) 
# change names using species name and the species alias
mar$species <- ifelse(!is.na(mar$alias), mar$alias, mar$species) 

# sum duplicates after name change (this also gets rid of the NA values)
mar <- mar %>%
  filter(!is.na(value)) %>%
  group_by(country, fao, environment, species, year, Taxon_code) %>%
    summarize(value = sum(value)) %>% 
  ungroup()

# remove extra fields
mar = mar %>% 
  select(country, fao, environment, species, year, value, Taxon_code)

# eliminate time-series with all 0s
mar <- mar %>%
  group_by(country, species) %>%
  mutate(total_value = sum(value)) %>%
  filter(total_value > 0) %>%
  select(-total_value) %>%
  ungroup()

Convert country names to OHI regions

# Divide mariculture from countries that we report as separate regions (assume equal production in all regions)
# Netherlands Antilles: Conch restoration among Aruba, Bonaire, Curacao
# Channel Islands: Jersey and Guernsey
# Bonaire/S.Eustatius/Saba
# Yugoslavia SFR: no longer a country after 1992

mar <- mar %>%
  mutate(country = ifelse(country=="R\xe9union", "Reunion", country)) %>%  # this one is hard to get right
  mar_split()  # function in mar_fxs.R

mar_rgn <- name_2_rgn(df_in = mar, 
                       fld_name='country', 
                       flds_unique=c('species', 'fao', 'environment', 'Taxon_code', 'year'))
## 
## These data were removed for not having any match in the lookup tables:
## 
## Yugoslavia SFR 
##              1 
## 
## These data were removed for not being of the proper rgn_type (eez,ohi_region) or mismatching region names in the lookup tables:
##                          tmp_type
## tmp_name                  disputed
##   Palestine, Occupied Tr.        8
## 
## DUPLICATES found. Consider using collapse2rgn to collapse duplicates (function in progress).
## # A tibble: 15 x 1
##                     country
##                       <chr>
## 1                     Aruba
## 2                   Bonaire
## 3                     China
## 4      China, Hong Kong SAR
## 5                   Curacao
## 6                Guadeloupe
## 7                      Guam
## 8                Martinique
## 9                Montenegro
## 10     Northern Mariana Is.
## 11       Russian Federation
## 12    Serbia and Montenegro
## 13 Tanzania, United Rep. of
## 14       Un. Sov. Soc. Rep.
## 15                 Zanzibar
### sum values of regions with multiple subregions
mar_rgn <- mar_rgn %>%
  group_by(fao, environment, species, year, Taxon_code, rgn_id) %>%
  summarize(value = sum(value)) %>%
  ungroup()

5.0.1 Gapfilling

Fill in missing years after first harvest with 0 values

mar_rgn_spread <- spread(mar_rgn, year, value) 
mar_rgn_gf <- gather(mar_rgn_spread, "year", "value", 6:ncol(mar_rgn_spread)) %>%
  arrange(rgn_id, species, year, Taxon_code, fao, environment)

mar_rgn_gf <- mar_rgn_gf %>%
  mutate(year = as.numeric(as.character(year))) %>%
  mutate(value_w_0 = ifelse(is.na(value), 0, value)) %>%
  group_by(fao, environment, species, Taxon_code, rgn_id) %>%
  mutate(cum_value = cumsum(value_w_0)) %>%
  ungroup() %>%
  filter(cum_value > 0) %>%
  mutate(gap_0_fill = ifelse(is.na(value), "NA_to_zero", "0")) %>%
  mutate(value = ifelse(is.na(value), 0, value)) %>%
  select(-cum_value, -value_w_0)
table(mar_rgn_gf$gap_0_fill)
## 
##          0 NA_to_zero 
##      24887       2943
## 2943 of these out of 24887+2943 cases

Remove time series with less than four non-zero datapoints (assume these are not established mariculture programs).

mar_rgn_gf = mar_rgn_gf %>% 
  group_by(rgn_id, species, fao, environment) %>%
  mutate (not_0 = length(value[value>0])) %>% 
  filter (not_0>3) %>%
  ungroup() %>% 
  select(rgn_id, species, fao, environment, year, value, Taxon_code, gap_0_fill)

Add a unique identifier per cultivated stock that describes species, fao region, and environment.

# add a unique identifier per cultivated stock
identifier = mar_rgn_gf %>% 
  select(rgn_id, species, fao, environment) %>% 
  unique() %>% 
  mutate(species_code = 1:n())

mar_rgn_gf = left_join(mar_rgn_gf, identifier)
## Joining, by = c("rgn_id", "species", "fao", "environment")
maric <- mar_rgn_gf

Save file to estimate total mariculture yield per country.

write.csv(maric, 'intermediate/MAR_FP_data.csv', row.names=FALSE)

6 Trujillo sustainability scores

(NOTE: These data have been simplified from last year, I eliminated all the fao/environment ditinctions that did not differ in regard to sustainability or genetic escapees. This just eliminates extra complexity that doesn’t alter scores.)

These data describe the sustainability and genetic escapes for country/species combinations (and, in a couple cases, environment and fao region combinations). In cases where these data were not available for a specific county/species, we averaged the data across taxonomic groups to gapfill the missing data.

Convert country names to OHI region names.

# Trujillo sustainability data:
sus = read.csv('raw/Truj_label_sust.csv', stringsAsFactors = FALSE, na.strings = NA)

## these need to be re-added (get cut when associated with region ids)
sus_no_rgn <- filter(sus, is.na(country))

# convert country names to OHI region names:
sus_rgn <- name_2_rgn(df_in = sus, 
                       fld_name='country', 
                       flds_unique=c('species_fao', 'fao', 'environment', 'species_Truj'))
## 
## These data were removed for not having any match in the lookup tables:
## < table of extent 0 >
sus_rgn <- bind_rows(sus_rgn, sus_no_rgn)

# check the fao spp list in the Trujillo sustainability file matches FAO mariculture species
setdiff(sus_rgn$species_fao, maric$species) # species that are no longer have mariculture industry or are not included due to being freshwater or non-food
##  [1] "River Plata mussel"    "Gracilaria seaweeds"  
##  [3] "Laver (Nori)"          "Atlantic wolffish"    
##  [5] "Spotted wolffish"      "Bagrid catfish"       
##  [7] "Freshwater fishes nei" "Tilapias nei"         
##  [9] "Torpedo catfishes nei" "Brill"                
## [11] "Razor clams nei"       "Brown seaweeds"       
## [13] "Brown seaweeds (Pac)"  "Silver carp"          
## [15] "Sturgeons nei"         "Blackchin tilapia"    
## [17] "Giant river prawn"     "Nile tilapia"         
## [19] "Aquatic plants nei"    "Tuna-like fishes nei" 
## [21] "Algae & marine plants" "All others"           
## [23] "Bivalve & gastropod"   "Blue tilapia"         
## [25] "Cephalopod"            "Crabs and lobsters"   
## [27] "Eucheuma seaweeds nei" "Fish"                 
## [29] "Importo totale"        "Inverts"              
## [31] "Japanese kelp"         "Molluscs"             
## [33] "Mozambique tilapia"    "Non-crustacean invert"
## [35] "Nori nei"              "Shrimp & prawn"       
## [37] "Spiny eucheuma"        "Trouts nei"           
## [39] "Tunicate"              "Urchin"               
## [41] "Wakame"                "Warty gracilaria"
sort(setdiff(maric$species, sus_rgn$species_fao)) # species with no Trujillo data
##   [1] "Akiami paste shrimp"            "Amberjacks nei"                
##   [3] "Anadara clams nei"              "Aquatic invertebrates nei"     
##   [5] "Areolate grouper"               "Atlantic ditch shrimp"         
##   [7] "Australian mussel"              "Banded carpet shell"           
##   [9] "Bastard halibut"                "Bastard halibuts nei"          
##  [11] "Bear paw clam"                  "Blackhead seabream"            
##  [13] "Blacklip pearl oyster"          "Blackspot(=red) seabream"      
##  [15] "blood cockle"                   "Blue crab"                     
##  [17] "Blue swimming crab"             "Brine shrimp"                  
##  [19] "Brown tiger prawn"              "Butter clam"                   
##  [21] "Caramote prawn"                 "Chars nei"                     
##  [23] "Chilean flat oyster"            "Chilean mussel"                
##  [25] "Cholga mussel"                  "Choro mussel"                  
##  [27] "Cobia"                          "Cockles nei"                   
##  [29] "Common dentex"                  "Common pandora"                
##  [31] "Common prawn"                   "Cortez oyster"                 
##  [33] "Crevalle jack"                  "Crimson seabream"              
##  [35] "Croakers, drums nei"            "Crocus giant clam"             
##  [37] "Donax clams"                    "Dotted gizzard shad"           
##  [39] "Drums nei"                      "Eastern king prawn"            
##  [41] "Eastern school shrimp"          "Elongate giant clam"           
##  [43] "European flounder"              "European whitefish"            
##  [45] "Filefishes, leatherjackets nei" "Filefishes nei"                
##  [47] "Finfishes nei"                  "Flathead lobster"              
##  [49] "Fleshy prawn"                   "Florida pompano"               
##  [51] "Fluted giant clam"              "Fourfinger threadfin"          
##  [53] "Gastropods nei"                 "Gazami crab"                   
##  [55] "Giant clam"                     "Globose clam"                  
##  [57] "Golden carpet shell"            "Golden trevally"               
##  [59] "Goldlined seabream"             "Goldsilk seabream"             
##  [61] "Greasy grouper"                 "Great Atlantic scallop"        
##  [63] "Greater amberjack"              "Green tiger prawn"             
##  [65] "Groundfishes nei"               "Gudgeons, sleepers nei"        
##  [67] "Hong Kong grouper"              "Hooded oyster"                 
##  [69] "Horned turban"                  "Horse mussels nei"             
##  [71] "Humpback grouper"               "Indian backwater oyster"       
##  [73] "Indo-Pacific swamp crab"        "Inflated ark"                  
##  [75] "Jacks, crevalles nei"           "Japanese abalone"              
##  [77] "Japanese amberjack"             "Japanese eel"                  
##  [79] "Japanese hard clam"             "Japanese jack mackerel"        
##  [81] "Japanese meagre"                "Japanese seabass"              
##  [83] "Japanese sea cucumber"          "Japanese spiny lobster"        
##  [85] "Jellyfishes nei"                "Korean rockfish"               
##  [87] "Largemouth black bass"          "Large yellow croaker"          
##  [89] "Lebranche mullet"               "Lefteye flounders nei"         
##  [91] "Mackerels nei"                  "Malabar grouper"               
##  [93] "Mangrove cupped oyster"         "Marbled spinefoot"             
##  [95] "Marine crabs nei"               "Meagre"                        
##  [97] "Mud spiny lobster"              "Northern quahog(=Hard clam)"   
##  [99] "Northern white shrimp"          "Octopuses, etc. nei"           
## [101] "Okhotsk atka mackerel"          "Olympia oyster"                
## [103] "Orange mud crab"                "Pacific bluefin tuna"          
## [105] "Pacific calico scallop"         "Pacific geoduck"               
## [107] "Pacific horse clam"             "Pacific lion's paw"            
## [109] "Pacific littleneck clam"        "Palaemonid shrimps nei"        
## [111] "Papuan black snapper"           "Pargo breams nei"              
## [113] "Pearl oyster shells nei"        "Penguin wing oyster"           
## [115] "Pen shells nei"                 "Peppery furrow"                
## [117] "Periwinkles nei"                "Pod razor shell"               
## [119] "Pollack"                        "Porgies, seabreams nei"        
## [121] "Portunus swimcrabs nei"         "Puffers nei"                   
## [123] "Queen scallop"                  "Red abalone"                   
## [125] "Red porgy"                      "Redtail prawn"                 
## [127] "Righteye flounders nei"         "Russell's snapper"             
## [129] "Salmonids nei"                  "Salmonoids nei"                
## [131] "Sand gaper"                     "Scats"                         
## [133] "Scorpionfishes nei"             "Sea cucumbers nei"             
## [135] "Sea snails"                     "Sea squirts nei"               
## [137] "Senegalese sole"                "Sharpsnout seabream"           
## [139] "Shi drum"                       "Sixfinger threadfin"           
## [141] "Slipper cupped oyster"          "Smooth giant clam"             
## [143] "Snappers, jobfishes nei"        "Snooks(=Robalos) nei"          
## [145] "Snubnose pompano"               "Sobaity seabream"              
## [147] "Solen razor clams nei"          "Soles nei"                     
## [149] "South American rock mussel"     "Southern Australia scallop"    
## [151] "Southern white shrimp"          "Speckled shrimp"               
## [153] "Spiny lobsters nei"             "Spotted rose snapper"          
## [155] "Spotted seabass"                "Squaretail mullet"             
## [157] "Stony sea urchin"               "Streaked spinefoot"            
## [159] "Striped bass, hybrid"           "Stromboid conchs nei"          
## [161] "Sydney cupped oyster"           "Thinlip grey mullet"           
## [163] "Tropical spiny lobsters nei"    "Trumpet emperor"               
## [165] "Variegated scallop"             "Venus clams nei"               
## [167] "Warty venus"                    "Whitemouth croaker"            
## [169] "White seabream"                 "White-spotted spinefoot"       
## [171] "White trevally"                 "Yellowfin seabream"

7 FAO maricultue and sustainability scores

Match the sustainability score to the FAO mariculture data.

The following joins the sustainability scores to regions/species that have Trujillo data.

table(sus_rgn$match_type)
## 
##     c_sp c_sp_env c_sp_fao  species    taxon 
##      301        4        2      110       12
# join taxa specific to country/species/environment
c_sp_env = sus_rgn %>% 
  filter(match_type == 'c_sp_env') %>% 
  select(rgn_id, species=species_fao, environment, Sust_c_sp_env = Maric_sustainability)

mar_sus <- maric %>%
  left_join(c_sp_env, by= c("species", "environment", "rgn_id"))

data.frame(filter(mar_sus, rgn_id==14 & species == "Barramundi"))
##    rgn_id    species                fao   environment year    value
## 1      14 Barramundi Pacific, Northwest Brackishwater 1989   560.00
## 2      14 Barramundi Pacific, Northwest Brackishwater 1990  1438.00
## 3      14 Barramundi Pacific, Northwest Brackishwater 1991   790.00
## 4      14 Barramundi Pacific, Northwest Brackishwater 1992  1374.00
## 5      14 Barramundi Pacific, Northwest Brackishwater 1993  1048.00
## 6      14 Barramundi Pacific, Northwest Brackishwater 1994  1804.00
## 7      14 Barramundi Pacific, Northwest Brackishwater 1995  1635.00
## 8      14 Barramundi Pacific, Northwest Brackishwater 1996  2202.00
## 9      14 Barramundi Pacific, Northwest        Marine 1996    16.00
## 10     14 Barramundi Pacific, Northwest Brackishwater 1997  2081.00
## 11     14 Barramundi Pacific, Northwest        Marine 1997    10.00
## 12     14 Barramundi Pacific, Northwest Brackishwater 1998  1637.00
## 13     14 Barramundi Pacific, Northwest        Marine 1998    12.00
## 14     14 Barramundi Pacific, Northwest Brackishwater 1999  1284.00
## 15     14 Barramundi Pacific, Northwest        Marine 1999     2.00
## 16     14 Barramundi Pacific, Northwest Brackishwater 2000  1075.00
## 17     14 Barramundi Pacific, Northwest        Marine 2000     3.00
## 18     14 Barramundi Pacific, Northwest Brackishwater 2001  1557.00
## 19     14 Barramundi Pacific, Northwest        Marine 2001    20.00
## 20     14 Barramundi Pacific, Northwest Brackishwater 2002  1798.00
## 21     14 Barramundi Pacific, Northwest        Marine 2002     0.00
## 22     14 Barramundi Pacific, Northwest Brackishwater 2003  1680.00
## 23     14 Barramundi Pacific, Northwest        Marine 2003     0.00
## 24     14 Barramundi Pacific, Northwest Brackishwater 2004  1504.00
## 25     14 Barramundi Pacific, Northwest        Marine 2004     0.00
## 26     14 Barramundi Pacific, Northwest Brackishwater 2005  3566.00
## 27     14 Barramundi Pacific, Northwest        Marine 2005     0.00
## 28     14 Barramundi Pacific, Northwest Brackishwater 2006  2437.00
## 29     14 Barramundi Pacific, Northwest        Marine 2006     0.00
## 30     14 Barramundi Pacific, Northwest Brackishwater 2007  2357.00
## 31     14 Barramundi Pacific, Northwest        Marine 2007     0.00
## 32     14 Barramundi Pacific, Northwest Brackishwater 2008  2693.00
## 33     14 Barramundi Pacific, Northwest        Marine 2008     0.00
## 34     14 Barramundi Pacific, Northwest Brackishwater 2009  2592.00
## 35     14 Barramundi Pacific, Northwest        Marine 2009     0.00
## 36     14 Barramundi Pacific, Northwest Brackishwater 2010  9038.00
## 37     14 Barramundi Pacific, Northwest        Marine 2010     0.00
## 38     14 Barramundi Pacific, Northwest Brackishwater 2011 11465.30
## 39     14 Barramundi Pacific, Northwest        Marine 2011     0.00
## 40     14 Barramundi Pacific, Northwest Brackishwater 2012  9327.00
## 41     14 Barramundi Pacific, Northwest        Marine 2012     0.00
## 42     14 Barramundi Pacific, Northwest Brackishwater 2013  6830.09
## 43     14 Barramundi Pacific, Northwest        Marine 2013     0.00
## 44     14 Barramundi Pacific, Northwest Brackishwater 2014  4133.03
## 45     14 Barramundi Pacific, Northwest        Marine 2014     0.00
##    Taxon_code gap_0_fill species_code Sust_c_sp_env
## 1           F          0           23          0.17
## 2           F          0           23          0.17
## 3           F          0           23          0.17
## 4           F          0           23          0.17
## 5           F          0           23          0.17
## 6           F          0           23          0.17
## 7           F          0           23          0.17
## 8           F          0           23          0.17
## 9           F          0           24          0.23
## 10          F          0           23          0.17
## 11          F          0           24          0.23
## 12          F          0           23          0.17
## 13          F          0           24          0.23
## 14          F          0           23          0.17
## 15          F          0           24          0.23
## 16          F          0           23          0.17
## 17          F          0           24          0.23
## 18          F          0           23          0.17
## 19          F          0           24          0.23
## 20          F          0           23          0.17
## 21          F          0           24          0.23
## 22          F          0           23          0.17
## 23          F          0           24          0.23
## 24          F          0           23          0.17
## 25          F          0           24          0.23
## 26          F          0           23          0.17
## 27          F          0           24          0.23
## 28          F          0           23          0.17
## 29          F          0           24          0.23
## 30          F          0           23          0.17
## 31          F          0           24          0.23
## 32          F          0           23          0.17
## 33          F          0           24          0.23
## 34          F          0           23          0.17
## 35          F          0           24          0.23
## 36          F          0           23          0.17
## 37          F          0           24          0.23
## 38          F          0           23          0.17
## 39          F          0           24          0.23
## 40          F          0           23          0.17
## 41          F          0           24          0.23
## 42          F          0           23          0.17
## 43          F          0           24          0.23
## 44          F          0           23          0.17
## 45          F          0           24          0.23
data.frame(filter(mar_sus, !is.na(Sust_c_sp_env)))
##    rgn_id      species                      fao   environment year
## 1      14   Barramundi       Pacific, Northwest Brackishwater 1989
## 2      14   Barramundi       Pacific, Northwest Brackishwater 1990
## 3      14   Barramundi       Pacific, Northwest Brackishwater 1991
## 4      14   Barramundi       Pacific, Northwest Brackishwater 1992
## 5      14   Barramundi       Pacific, Northwest Brackishwater 1993
## 6      14   Barramundi       Pacific, Northwest Brackishwater 1994
## 7      14   Barramundi       Pacific, Northwest Brackishwater 1995
## 8      14   Barramundi       Pacific, Northwest Brackishwater 1996
## 9      14   Barramundi       Pacific, Northwest        Marine 1996
## 10     14   Barramundi       Pacific, Northwest Brackishwater 1997
## 11     14   Barramundi       Pacific, Northwest        Marine 1997
## 12     14   Barramundi       Pacific, Northwest Brackishwater 1998
## 13     14   Barramundi       Pacific, Northwest        Marine 1998
## 14     14   Barramundi       Pacific, Northwest Brackishwater 1999
## 15     14   Barramundi       Pacific, Northwest        Marine 1999
## 16     14   Barramundi       Pacific, Northwest Brackishwater 2000
## 17     14   Barramundi       Pacific, Northwest        Marine 2000
## 18     14   Barramundi       Pacific, Northwest Brackishwater 2001
## 19     14   Barramundi       Pacific, Northwest        Marine 2001
## 20     14   Barramundi       Pacific, Northwest Brackishwater 2002
## 21     14   Barramundi       Pacific, Northwest        Marine 2002
## 22     14   Barramundi       Pacific, Northwest Brackishwater 2003
## 23     14   Barramundi       Pacific, Northwest        Marine 2003
## 24     14   Barramundi       Pacific, Northwest Brackishwater 2004
## 25     14   Barramundi       Pacific, Northwest        Marine 2004
## 26     14   Barramundi       Pacific, Northwest Brackishwater 2005
## 27     14   Barramundi       Pacific, Northwest        Marine 2005
## 28     14   Barramundi       Pacific, Northwest Brackishwater 2006
## 29     14   Barramundi       Pacific, Northwest        Marine 2006
## 30     14   Barramundi       Pacific, Northwest Brackishwater 2007
## 31     14   Barramundi       Pacific, Northwest        Marine 2007
## 32     14   Barramundi       Pacific, Northwest Brackishwater 2008
## 33     14   Barramundi       Pacific, Northwest        Marine 2008
## 34     14   Barramundi       Pacific, Northwest Brackishwater 2009
## 35     14   Barramundi       Pacific, Northwest        Marine 2009
## 36     14   Barramundi       Pacific, Northwest Brackishwater 2010
## 37     14   Barramundi       Pacific, Northwest        Marine 2010
## 38     14   Barramundi       Pacific, Northwest Brackishwater 2011
## 39     14   Barramundi       Pacific, Northwest        Marine 2011
## 40     14   Barramundi       Pacific, Northwest Brackishwater 2012
## 41     14   Barramundi       Pacific, Northwest        Marine 2012
## 42     14   Barramundi       Pacific, Northwest Brackishwater 2013
## 43     14   Barramundi       Pacific, Northwest        Marine 2013
## 44     14   Barramundi       Pacific, Northwest Brackishwater 2014
## 45     14   Barramundi       Pacific, Northwest        Marine 2014
## 46     15 Banana prawn Pacific, Western Central Brackishwater 1973
## 47     15 Banana prawn Pacific, Western Central Brackishwater 1974
## 48     15 Banana prawn Pacific, Western Central Brackishwater 1975
## 49     15 Banana prawn Pacific, Western Central Brackishwater 1976
## 50     15 Banana prawn Pacific, Western Central Brackishwater 1977
## 51     15 Banana prawn Pacific, Western Central Brackishwater 1978
## 52     15 Banana prawn Pacific, Western Central Brackishwater 1979
## 53     15 Banana prawn Pacific, Western Central Brackishwater 1980
## 54     15 Banana prawn Pacific, Western Central Brackishwater 1981
## 55     15 Banana prawn Pacific, Western Central Brackishwater 1982
## 56     15 Banana prawn Pacific, Western Central Brackishwater 1983
## 57     15 Banana prawn Pacific, Western Central Brackishwater 1984
## 58     15 Banana prawn Pacific, Western Central Brackishwater 1985
## 59     15 Banana prawn Pacific, Western Central Brackishwater 1986
## 60     15 Banana prawn Pacific, Western Central Brackishwater 1987
## 61     15 Banana prawn Pacific, Western Central Brackishwater 1988
## 62     15 Banana prawn Pacific, Western Central Brackishwater 1989
## 63     15 Banana prawn Pacific, Western Central Brackishwater 1990
## 64     15 Banana prawn Pacific, Western Central Brackishwater 1991
## 65     15 Banana prawn Pacific, Western Central Brackishwater 1992
## 66     15 Banana prawn Pacific, Western Central Brackishwater 1993
## 67     15 Banana prawn Pacific, Western Central Brackishwater 1994
## 68     15 Banana prawn Pacific, Western Central Brackishwater 1995
## 69     15 Banana prawn Pacific, Western Central Brackishwater 1996
## 70     15 Banana prawn Pacific, Western Central Brackishwater 1997
## 71     15 Banana prawn Pacific, Western Central Brackishwater 1998
## 72     15 Banana prawn Pacific, Western Central Brackishwater 1999
## 73     15 Banana prawn Pacific, Western Central Brackishwater 2000
## 74     15 Banana prawn Pacific, Western Central Brackishwater 2001
## 75     15 Banana prawn Pacific, Western Central Brackishwater 2002
## 76     15 Banana prawn Pacific, Western Central Brackishwater 2003
## 77     15 Banana prawn Pacific, Western Central Brackishwater 2004
## 78     15 Banana prawn Pacific, Western Central Brackishwater 2005
## 79     15 Banana prawn Pacific, Western Central Brackishwater 2006
## 80     15 Banana prawn Pacific, Western Central Brackishwater 2007
## 81     15 Banana prawn Pacific, Western Central Brackishwater 2008
## 82     15 Banana prawn Pacific, Western Central Brackishwater 2009
## 83     15 Banana prawn Pacific, Western Central Brackishwater 2010
## 84     15 Banana prawn Pacific, Western Central Brackishwater 2011
## 85     15 Banana prawn Pacific, Western Central Brackishwater 2012
## 86     15 Banana prawn Pacific, Western Central Brackishwater 2013
## 87     15 Banana prawn Pacific, Western Central Brackishwater 2014
##       value Taxon_code gap_0_fill species_code Sust_c_sp_env
## 1    560.00          F          0           23          0.17
## 2   1438.00          F          0           23          0.17
## 3    790.00          F          0           23          0.17
## 4   1374.00          F          0           23          0.17
## 5   1048.00          F          0           23          0.17
## 6   1804.00          F          0           23          0.17
## 7   1635.00          F          0           23          0.17
## 8   2202.00          F          0           23          0.17
## 9     16.00          F          0           24          0.23
## 10  2081.00          F          0           23          0.17
## 11    10.00          F          0           24          0.23
## 12  1637.00          F          0           23          0.17
## 13    12.00          F          0           24          0.23
## 14  1284.00          F          0           23          0.17
## 15     2.00          F          0           24          0.23
## 16  1075.00          F          0           23          0.17
## 17     3.00          F          0           24          0.23
## 18  1557.00          F          0           23          0.17
## 19    20.00          F          0           24          0.23
## 20  1798.00          F          0           23          0.17
## 21     0.00          F          0           24          0.23
## 22  1680.00          F          0           23          0.17
## 23     0.00          F          0           24          0.23
## 24  1504.00          F          0           23          0.17
## 25     0.00          F          0           24          0.23
## 26  3566.00          F          0           23          0.17
## 27     0.00          F          0           24          0.23
## 28  2437.00          F          0           23          0.17
## 29     0.00          F          0           24          0.23
## 30  2357.00          F          0           23          0.17
## 31     0.00          F          0           24          0.23
## 32  2693.00          F          0           23          0.17
## 33     0.00          F          0           24          0.23
## 34  2592.00          F          0           23          0.17
## 35     0.00          F          0           24          0.23
## 36  9038.00          F          0           23          0.17
## 37     0.00          F          0           24          0.23
## 38 11465.30          F          0           23          0.17
## 39     0.00          F          0           24          0.23
## 40  9327.00          F          0           23          0.17
## 41     0.00          F          0           24          0.23
## 42  6830.09          F          0           23          0.17
## 43     0.00          F          0           24          0.23
## 44  4133.03          F          0           23          0.17
## 45     0.00          F          0           24          0.23
## 46    70.00         SH          0           68          0.27
## 47   104.00         SH          0           68          0.27
## 48   128.00         SH          0           68          0.27
## 49   158.00         SH          0           68          0.27
## 50   195.00         SH          0           68          0.27
## 51   241.00         SH          0           68          0.27
## 52   140.00         SH          0           68          0.27
## 53    64.00         SH          0           68          0.27
## 54   119.00         SH          0           68          0.27
## 55   126.00         SH          0           68          0.27
## 56   909.00         SH          0           68          0.27
## 57  2500.00         SH          0           68          0.27
## 58  2500.00         SH          0           68          0.27
## 59  2481.00         SH          0           68          0.27
## 60  2690.00         SH          0           68          0.27
## 61  2727.00         SH          0           68          0.27
## 62  3458.00         SH          0           68          0.27
## 63   779.00         SH          0           68          0.27
## 64  1445.00         SH          0           68          0.27
## 65   760.00         SH          0           68          0.27
## 66   230.00         SH          0           68          0.27
## 67   378.00         SH          0           68          0.27
## 68   346.00         SH          0           68          0.27
## 69   709.00         SH          0           68          0.27
## 70   687.00         SH          0           68          0.27
## 71   741.00         SH          0           68          0.27
## 72  1038.00         SH          0           68          0.27
## 73  1014.00         SH          0           68          0.27
## 74  1276.00         SH          0           68          0.27
## 75  1541.00         SH          0           68          0.27
## 76  1517.00         SH          0           68          0.27
## 77  1471.00         SH          0           68          0.27
## 78  1519.00         SH          0           68          0.27
## 79  1647.00         SH          0           68          0.27
## 80  2115.00         SH          0           68          0.27
## 81  2070.00         SH          0           68          0.27
## 82  2204.00         SH          0           68          0.27
## 83  2077.00         SH          0           68          0.27
## 84  1974.00         SH          0           68          0.27
## 85  1879.00         SH          0           68          0.27
## 86  1871.00         SH          0           68          0.27
## 87  1827.00         SH          0           68          0.27
# join taxa specific to country/species/fao region
c_sp_fao = sus_rgn %>% 
  filter(match_type == 'c_sp_fao') %>% 
  select(rgn_id, species=species_fao, fao, Sust_c_sp_fao = Maric_sustainability)

mar_sus <- mar_sus %>%
  left_join(c_sp_fao, by= c("species", "fao", "rgn_id"))

data.frame(filter(mar_sus, rgn_id==218 & species == "Atlantic salmon"))
##    rgn_id         species                 fao environment year value
## 1     218 Atlantic salmon Atlantic, Northwest      Marine 1979     5
## 2     218 Atlantic salmon Atlantic, Northwest      Marine 1980    27
## 3     218 Atlantic salmon Atlantic, Northwest      Marine 1981    76
## 4     218 Atlantic salmon Atlantic, Northwest      Marine 1982   143
## 5     218 Atlantic salmon Atlantic, Northwest      Marine 1983    68
## 6     218 Atlantic salmon Atlantic, Northwest      Marine 1984   222
## 7     218 Atlantic salmon Atlantic, Northwest      Marine 1985   349
## 8     218 Atlantic salmon Atlantic, Northwest      Marine 1986   682
## 9     218 Atlantic salmon Atlantic, Northwest      Marine 1987  1382
## 10    218 Atlantic salmon  Pacific, Northeast      Marine 1987     3
## 11    218 Atlantic salmon Atlantic, Northwest      Marine 1988  3351
## 12    218 Atlantic salmon  Pacific, Northeast      Marine 1988    80
## 13    218 Atlantic salmon Atlantic, Northwest      Marine 1989  4687
## 14    218 Atlantic salmon  Pacific, Northeast      Marine 1989  1280
## 15    218 Atlantic salmon Atlantic, Northwest      Marine 1990  7835
## 16    218 Atlantic salmon  Pacific, Northeast      Marine 1990  1790
## 17    218 Atlantic salmon Atlantic, Northwest      Marine 1991  9848
## 18    218 Atlantic salmon  Pacific, Northeast      Marine 1991  3651
## 19    218 Atlantic salmon Atlantic, Northwest      Marine 1992 10520
## 20    218 Atlantic salmon  Pacific, Northeast      Marine 1992  6785
## 21    218 Atlantic salmon Atlantic, Northwest      Marine 1993 11123
## 22    218 Atlantic salmon  Pacific, Northeast      Marine 1993 12360
## 23    218 Atlantic salmon Atlantic, Northwest      Marine 1994 12426
## 24    218 Atlantic salmon  Pacific, Northeast      Marine 1994 15347
## 25    218 Atlantic salmon Atlantic, Northwest      Marine 1995 15235
## 26    218 Atlantic salmon  Pacific, Northeast      Marine 1995 18439
## 27    218 Atlantic salmon Atlantic, Northwest      Marine 1996 17800
## 28    218 Atlantic salmon  Pacific, Northeast      Marine 1996 18675
## 29    218 Atlantic salmon Atlantic, Northwest      Marine 1997 20310
## 30    218 Atlantic salmon  Pacific, Northeast      Marine 1997 30705
## 31    218 Atlantic salmon Atlantic, Northwest      Marine 1998 16418
## 32    218 Atlantic salmon  Pacific, Northeast      Marine 1998 33057
## 33    218 Atlantic salmon Atlantic, Northwest      Marine 1999 23190
## 34    218 Atlantic salmon  Pacific, Northeast      Marine 1999 38800
## 35    218 Atlantic salmon Atlantic, Northwest      Marine 2000 33195
## 36    218 Atlantic salmon  Pacific, Northeast      Marine 2000 39300
## 37    218 Atlantic salmon Atlantic, Northwest      Marine 2001 37606
## 38    218 Atlantic salmon  Pacific, Northeast      Marine 2001 58000
## 39    218 Atlantic salmon Atlantic, Northwest      Marine 2002 42121
## 40    218 Atlantic salmon  Pacific, Northeast      Marine 2002 72800
## 41    218 Atlantic salmon Atlantic, Northwest      Marine 2003 34550
## 42    218 Atlantic salmon  Pacific, Northeast      Marine 2003 72678
## 43    218 Atlantic salmon Atlantic, Northwest      Marine 2004 35000
## 44    218 Atlantic salmon  Pacific, Northeast      Marine 2004 61774
## 45    218 Atlantic salmon Atlantic, Northwest      Marine 2005 35000
## 46    218 Atlantic salmon  Pacific, Northeast      Marine 2005 63370
## 47    218 Atlantic salmon Atlantic, Northwest      Marine 2006 47880
## 48    218 Atlantic salmon  Pacific, Northeast      Marine 2006 70181
## 49    218 Atlantic salmon Atlantic, Northwest      Marine 2007 31511
## 50    218 Atlantic salmon  Pacific, Northeast      Marine 2007 70998
## 51    218 Atlantic salmon Atlantic, Northwest      Marine 2008 30810
## 52    218 Atlantic salmon  Pacific, Northeast      Marine 2008 73265
## 53    218 Atlantic salmon Atlantic, Northwest      Marine 2009 31550
## 54    218 Atlantic salmon  Pacific, Northeast      Marine 2009 68662
## 55    218 Atlantic salmon Atlantic, Northwest      Marine 2010 30713
## 56    218 Atlantic salmon  Pacific, Northeast      Marine 2010 70831
## 57    218 Atlantic salmon Atlantic, Northwest      Marine 2011 27184
## 58    218 Atlantic salmon  Pacific, Northeast      Marine 2011 83144
## 59    218 Atlantic salmon Atlantic, Northwest      Marine 2012 36120
## 60    218 Atlantic salmon  Pacific, Northeast      Marine 2012 79981
## 61    218 Atlantic salmon Atlantic, Northwest      Marine 2013 25453
## 62    218 Atlantic salmon  Pacific, Northeast      Marine 2013 74673
## 63    218 Atlantic salmon Atlantic, Northwest      Marine 2014 24008
## 64    218 Atlantic salmon  Pacific, Northeast      Marine 2014 54971
##    Taxon_code gap_0_fill species_code Sust_c_sp_env Sust_c_sp_fao
## 1           F          0          988            NA          0.17
## 2           F          0          988            NA          0.17
## 3           F          0          988            NA          0.17
## 4           F          0          988            NA          0.17
## 5           F          0          988            NA          0.17
## 6           F          0          988            NA          0.17
## 7           F          0          988            NA          0.17
## 8           F          0          988            NA          0.17
## 9           F          0          988            NA          0.17
## 10          F          0          989            NA          0.27
## 11          F          0          988            NA          0.17
## 12          F          0          989            NA          0.27
## 13          F          0          988            NA          0.17
## 14          F          0          989            NA          0.27
## 15          F          0          988            NA          0.17
## 16          F          0          989            NA          0.27
## 17          F          0          988            NA          0.17
## 18          F          0          989            NA          0.27
## 19          F          0          988            NA          0.17
## 20          F          0          989            NA          0.27
## 21          F          0          988            NA          0.17
## 22          F          0          989            NA          0.27
## 23          F          0          988            NA          0.17
## 24          F          0          989            NA          0.27
## 25          F          0          988            NA          0.17
## 26          F          0          989            NA          0.27
## 27          F          0          988            NA          0.17
## 28          F          0          989            NA          0.27
## 29          F          0          988            NA          0.17
## 30          F          0          989            NA          0.27
## 31          F          0          988            NA          0.17
## 32          F          0          989            NA          0.27
## 33          F          0          988            NA          0.17
## 34          F          0          989            NA          0.27
## 35          F          0          988            NA          0.17
## 36          F          0          989            NA          0.27
## 37          F          0          988            NA          0.17
## 38          F          0          989            NA          0.27
## 39          F          0          988            NA          0.17
## 40          F          0          989            NA          0.27
## 41          F          0          988            NA          0.17
## 42          F          0          989            NA          0.27
## 43          F          0          988            NA          0.17
## 44          F          0          989            NA          0.27
## 45          F          0          988            NA          0.17
## 46          F          0          989            NA          0.27
## 47          F          0          988            NA          0.17
## 48          F          0          989            NA          0.27
## 49          F          0          988            NA          0.17
## 50          F          0          989            NA          0.27
## 51          F          0          988            NA          0.17
## 52          F          0          989            NA          0.27
## 53          F          0          988            NA          0.17
## 54          F          0          989            NA          0.27
## 55          F          0          988            NA          0.17
## 56          F          0          989            NA          0.27
## 57          F          0          988            NA          0.17
## 58          F          0          989            NA          0.27
## 59          F          0          988            NA          0.17
## 60          F          0          989            NA          0.27
## 61          F          0          988            NA          0.17
## 62          F          0          989            NA          0.27
## 63          F          0          988            NA          0.17
## 64          F          0          989            NA          0.27
data.frame(filter(mar_sus, !is.na(Sust_c_sp_fao)))
##    rgn_id         species                 fao environment year value
## 1     218 Atlantic salmon Atlantic, Northwest      Marine 1979     5
## 2     218 Atlantic salmon Atlantic, Northwest      Marine 1980    27
## 3     218 Atlantic salmon Atlantic, Northwest      Marine 1981    76
## 4     218 Atlantic salmon Atlantic, Northwest      Marine 1982   143
## 5     218 Atlantic salmon Atlantic, Northwest      Marine 1983    68
## 6     218 Atlantic salmon Atlantic, Northwest      Marine 1984   222
## 7     218 Atlantic salmon Atlantic, Northwest      Marine 1985   349
## 8     218 Atlantic salmon Atlantic, Northwest      Marine 1986   682
## 9     218 Atlantic salmon Atlantic, Northwest      Marine 1987  1382
## 10    218 Atlantic salmon  Pacific, Northeast      Marine 1987     3
## 11    218 Atlantic salmon Atlantic, Northwest      Marine 1988  3351
## 12    218 Atlantic salmon  Pacific, Northeast      Marine 1988    80
## 13    218 Atlantic salmon Atlantic, Northwest      Marine 1989  4687
## 14    218 Atlantic salmon  Pacific, Northeast      Marine 1989  1280
## 15    218 Atlantic salmon Atlantic, Northwest      Marine 1990  7835
## 16    218 Atlantic salmon  Pacific, Northeast      Marine 1990  1790
## 17    218 Atlantic salmon Atlantic, Northwest      Marine 1991  9848
## 18    218 Atlantic salmon  Pacific, Northeast      Marine 1991  3651
## 19    218 Atlantic salmon Atlantic, Northwest      Marine 1992 10520
## 20    218 Atlantic salmon  Pacific, Northeast      Marine 1992  6785
## 21    218 Atlantic salmon Atlantic, Northwest      Marine 1993 11123
## 22    218 Atlantic salmon  Pacific, Northeast      Marine 1993 12360
## 23    218 Atlantic salmon Atlantic, Northwest      Marine 1994 12426
## 24    218 Atlantic salmon  Pacific, Northeast      Marine 1994 15347
## 25    218 Atlantic salmon Atlantic, Northwest      Marine 1995 15235
## 26    218 Atlantic salmon  Pacific, Northeast      Marine 1995 18439
## 27    218 Atlantic salmon Atlantic, Northwest      Marine 1996 17800
## 28    218 Atlantic salmon  Pacific, Northeast      Marine 1996 18675
## 29    218 Atlantic salmon Atlantic, Northwest      Marine 1997 20310
## 30    218 Atlantic salmon  Pacific, Northeast      Marine 1997 30705
## 31    218 Atlantic salmon Atlantic, Northwest      Marine 1998 16418
## 32    218 Atlantic salmon  Pacific, Northeast      Marine 1998 33057
## 33    218 Atlantic salmon Atlantic, Northwest      Marine 1999 23190
## 34    218 Atlantic salmon  Pacific, Northeast      Marine 1999 38800
## 35    218 Atlantic salmon Atlantic, Northwest      Marine 2000 33195
## 36    218 Atlantic salmon  Pacific, Northeast      Marine 2000 39300
## 37    218 Atlantic salmon Atlantic, Northwest      Marine 2001 37606
## 38    218 Atlantic salmon  Pacific, Northeast      Marine 2001 58000
## 39    218 Atlantic salmon Atlantic, Northwest      Marine 2002 42121
## 40    218 Atlantic salmon  Pacific, Northeast      Marine 2002 72800
## 41    218 Atlantic salmon Atlantic, Northwest      Marine 2003 34550
## 42    218 Atlantic salmon  Pacific, Northeast      Marine 2003 72678
## 43    218 Atlantic salmon Atlantic, Northwest      Marine 2004 35000
## 44    218 Atlantic salmon  Pacific, Northeast      Marine 2004 61774
## 45    218 Atlantic salmon Atlantic, Northwest      Marine 2005 35000
## 46    218 Atlantic salmon  Pacific, Northeast      Marine 2005 63370
## 47    218 Atlantic salmon Atlantic, Northwest      Marine 2006 47880
## 48    218 Atlantic salmon  Pacific, Northeast      Marine 2006 70181
## 49    218 Atlantic salmon Atlantic, Northwest      Marine 2007 31511
## 50    218 Atlantic salmon  Pacific, Northeast      Marine 2007 70998
## 51    218 Atlantic salmon Atlantic, Northwest      Marine 2008 30810
## 52    218 Atlantic salmon  Pacific, Northeast      Marine 2008 73265
## 53    218 Atlantic salmon Atlantic, Northwest      Marine 2009 31550
## 54    218 Atlantic salmon  Pacific, Northeast      Marine 2009 68662
## 55    218 Atlantic salmon Atlantic, Northwest      Marine 2010 30713
## 56    218 Atlantic salmon  Pacific, Northeast      Marine 2010 70831
## 57    218 Atlantic salmon Atlantic, Northwest      Marine 2011 27184
## 58    218 Atlantic salmon  Pacific, Northeast      Marine 2011 83144
## 59    218 Atlantic salmon Atlantic, Northwest      Marine 2012 36120
## 60    218 Atlantic salmon  Pacific, Northeast      Marine 2012 79981
## 61    218 Atlantic salmon Atlantic, Northwest      Marine 2013 25453
## 62    218 Atlantic salmon  Pacific, Northeast      Marine 2013 74673
## 63    218 Atlantic salmon Atlantic, Northwest      Marine 2014 24008
## 64    218 Atlantic salmon  Pacific, Northeast      Marine 2014 54971
##    Taxon_code gap_0_fill species_code Sust_c_sp_env Sust_c_sp_fao
## 1           F          0          988            NA          0.17
## 2           F          0          988            NA          0.17
## 3           F          0          988            NA          0.17
## 4           F          0          988            NA          0.17
## 5           F          0          988            NA          0.17
## 6           F          0          988            NA          0.17
## 7           F          0          988            NA          0.17
## 8           F          0          988            NA          0.17
## 9           F          0          988            NA          0.17
## 10          F          0          989            NA          0.27
## 11          F          0          988            NA          0.17
## 12          F          0          989            NA          0.27
## 13          F          0          988            NA          0.17
## 14          F          0          989            NA          0.27
## 15          F          0          988            NA          0.17
## 16          F          0          989            NA          0.27
## 17          F          0          988            NA          0.17
## 18          F          0          989            NA          0.27
## 19          F          0          988            NA          0.17
## 20          F          0          989            NA          0.27
## 21          F          0          988            NA          0.17
## 22          F          0          989            NA          0.27
## 23          F          0          988            NA          0.17
## 24          F          0          989            NA          0.27
## 25          F          0          988            NA          0.17
## 26          F          0          989            NA          0.27
## 27          F          0          988            NA          0.17
## 28          F          0          989            NA          0.27
## 29          F          0          988            NA          0.17
## 30          F          0          989            NA          0.27
## 31          F          0          988            NA          0.17
## 32          F          0          989            NA          0.27
## 33          F          0          988            NA          0.17
## 34          F          0          989            NA          0.27
## 35          F          0          988            NA          0.17
## 36          F          0          989            NA          0.27
## 37          F          0          988            NA          0.17
## 38          F          0          989            NA          0.27
## 39          F          0          988            NA          0.17
## 40          F          0          989            NA          0.27
## 41          F          0          988            NA          0.17
## 42          F          0          989            NA          0.27
## 43          F          0          988            NA          0.17
## 44          F          0          989            NA          0.27
## 45          F          0          988            NA          0.17
## 46          F          0          989            NA          0.27
## 47          F          0          988            NA          0.17
## 48          F          0          989            NA          0.27
## 49          F          0          988            NA          0.17
## 50          F          0          989            NA          0.27
## 51          F          0          988            NA          0.17
## 52          F          0          989            NA          0.27
## 53          F          0          988            NA          0.17
## 54          F          0          989            NA          0.27
## 55          F          0          988            NA          0.17
## 56          F          0          989            NA          0.27
## 57          F          0          988            NA          0.17
## 58          F          0          989            NA          0.27
## 59          F          0          988            NA          0.17
## 60          F          0          989            NA          0.27
## 61          F          0          988            NA          0.17
## 62          F          0          989            NA          0.27
## 63          F          0          988            NA          0.17
## 64          F          0          989            NA          0.27
# join taxa specific to country/species
c_sp = sus_rgn %>% 
  filter(match_type == 'c_sp') %>% 
  select(rgn_id, species=species_fao, Sust_c_sp = Maric_sustainability)

mar_sus <- mar_sus %>%
  left_join(c_sp, by= c("species", "rgn_id"))
summary(mar_sus)
##      rgn_id        species              fao            environment       
##  Min.   :  5.0   Length:25849       Length:25849       Length:25849      
##  1st Qu.: 51.0   Class :character   Class :character   Class :character  
##  Median :163.0   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :130.2                                                           
##  3rd Qu.:205.0                                                           
##  Max.   :250.0                                                           
##                                                                          
##       year          value          Taxon_code         gap_0_fill       
##  Min.   :1950   Min.   :      0   Length:25849       Length:25849      
##  1st Qu.:1990   1st Qu.:      1   Class :character   Class :character  
##  Median :2001   Median :    100   Mode  :character   Mode  :character  
##  Mean   :1997   Mean   :  17082                                        
##  3rd Qu.:2008   3rd Qu.:   1860                                        
##  Max.   :2014   Max.   :4352694                                        
##                                                                        
##   species_code    Sust_c_sp_env   Sust_c_sp_fao     Sust_c_sp    
##  Min.   :   1.0   Min.   :0.170   Min.   :0.170   Min.   :0.100  
##  1st Qu.: 241.0   1st Qu.:0.170   1st Qu.:0.170   1st Qu.:0.330  
##  Median : 530.0   Median :0.230   Median :0.170   Median :0.500  
##  Mean   : 528.5   Mean   :0.231   Mean   :0.214   Mean   :0.521  
##  3rd Qu.: 825.0   3rd Qu.:0.270   3rd Qu.:0.270   3rd Qu.:0.770  
##  Max.   :1052.0   Max.   :0.270   Max.   :0.270   Max.   :1.000  
##                   NA's   :25762   NA's   :25785   NA's   :16388
### merge these into a single sustainability score
mar_sus = mar_sus %>% 
  mutate(Sust = ifelse(!is.na(Sust_c_sp_env), Sust_c_sp_env, Sust_c_sp_fao)) %>%
  mutate(Sust = ifelse(is.na(Sust), Sust_c_sp, Sust)) %>%
  select(-Sust_c_sp_env, -Sust_c_sp_fao, -Sust_c_sp)

This joins the sustainability data that is gapfilled either at the species level (average of specific species/genera across regions) or at a higher course taxonomic levels and documents which data are gapfilled and how.

## Gapfilled at the species/genera level:
gf_sp_sus <- filter(sus_rgn, gapfill != "actuals" & match_type == "species") %>%
  select(species = species_fao, gapfill, Sust_gf_sp = Maric_sustainability)

## check that there are no duplicated species_fao
gf_sp_sus[duplicated(gf_sp_sus$species), ]
## [1] species    gapfill    Sust_gf_sp
## <0 rows> (or 0-length row.names)
# Match gapfilling values by species
mar_sus_gf = mar_sus %>%
  left_join(gf_sp_sus, by = 'species')


# Gapfilled at the coarse taxon level:
gf_taxon_sus <- filter(sus_rgn, gapfill != "actuals" & match_type == "taxon") %>%
  select(Taxon_code=taxon, Sust_gf_taxon = Maric_sustainability)

# Match gapfilling values by species
mar_sus_gf = mar_sus_gf %>%
  left_join(gf_taxon_sus, by = c('Taxon_code'))

summary(mar_sus_gf)
##      rgn_id        species              fao            environment       
##  Min.   :  5.0   Length:25849       Length:25849       Length:25849      
##  1st Qu.: 51.0   Class :character   Class :character   Class :character  
##  Median :163.0   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :130.2                                                           
##  3rd Qu.:205.0                                                           
##  Max.   :250.0                                                           
##                                                                          
##       year          value          Taxon_code         gap_0_fill       
##  Min.   :1950   Min.   :      0   Length:25849       Length:25849      
##  1st Qu.:1990   1st Qu.:      1   Class :character   Class :character  
##  Median :2001   Median :    100   Mode  :character   Mode  :character  
##  Mean   :1997   Mean   :  17082                                        
##  3rd Qu.:2008   3rd Qu.:   1860                                        
##  Max.   :2014   Max.   :4352694                                        
##                                                                        
##   species_code         Sust         gapfill            Sust_gf_sp   
##  Min.   :   1.0   Min.   :0.100   Length:25849       Min.   :0.100  
##  1st Qu.: 241.0   1st Qu.:0.330   Class :character   1st Qu.:0.375  
##  Median : 530.0   Median :0.470   Mode  :character   Median :0.478  
##  Mean   : 528.5   Mean   :0.516                      Mean   :0.548  
##  3rd Qu.: 825.0   3rd Qu.:0.770                      3rd Qu.:0.757  
##  Max.   :1052.0   Max.   :1.000                      Max.   :0.902  
##                   NA's   :16237                      NA's   :7847   
##  Sust_gf_taxon   
##  Min.   :0.3667  
##  1st Qu.:0.4440  
##  Median :0.4440  
##  Mean   :0.5594  
##  3rd Qu.:0.8118  
##  Max.   :0.8118  
## 
table(mar_sus_gf$gapfill)
## 
## genus_average    sp_average 
##          2177         15825
#Obtain a sustainability score for each record, and a book-keeping column of whether it's actual or gap-filled
mar_sus_final = mar_sus_gf %>% 
  mutate(gapfill = ifelse(!is.na(Sust), "none", gapfill)) %>% 
  mutate(Sust = ifelse(is.na(Sust), Sust_gf_sp, Sust)) %>%
  mutate(gapfill = ifelse(is.na(Sust), "taxon_average", gapfill)) %>%
  mutate(Sust = ifelse(is.na(Sust), Sust_gf_taxon, Sust)) %>%
  mutate(taxa_code = paste(species, species_code, sep="_")) %>%
  select(rgn_id, species, species_code, taxa_code, year, gapfill_sus = gapfill, gapfill_fao = gap_0_fill, tonnes=value, Sust)


## save data layers
mar_harvest_tonnes = mar_sus_final %>%
  select(rgn_id, taxa_code, year, tonnes)
anyDuplicated(mar_harvest_tonnes)
## [1] 0
write.csv(mar_harvest_tonnes, 'output/mar_harvest_tonnes.csv', row.names=F)

mar_harvest_tonnes_gf = mar_sus_final %>%
  select(rgn_id, taxa_code, year, tonnes=gapfill_fao)
write.csv(mar_harvest_tonnes, 'output/mar_harvest_tonnes_gf.csv', row.names=F)


mar_sustainability_score = mar_sus_final %>% 
  select(rgn_id, taxa_code, sust_coeff = Sust) %>% 
  unique()
anyDuplicated(mar_sustainability_score)
## [1] 0
write.csv(mar_sustainability_score, 'output/mar_sustainability.csv', row.names=F)

mar_sustainability_score_gf = mar_sus_final %>% 
  select(rgn_id, taxa_code, sust_coeff = gapfill_sus) %>% 
  unique()
write.csv(mar_sustainability_score, 'output/mar_sustainability_gf.csv', row.names=F)

8 Genetic escapes data

These data are used as a pressure layer to describe the risk of genetic escapees due to mariculture.

First merge with the species data (no gapfilling) for each country/species/fao region combination.

# can eliminate the environment category because these have the same scores
esc = sus_rgn %>% 
  filter(!is.na(Genetic.escapees)) %>%
  mutate(match_type = ifelse(match_type == "c_sp_env", "c_sp", match_type)) %>%
  group_by(rgn_id, species=species_fao, fao, match_type, taxon, gapfill) %>%
  summarize(Genetic.escapees = mean(Genetic.escapees)) %>%
  ungroup()
  
# join taxa specific to country/species/fao
c_sp_fao = esc %>% 
  filter(match_type == 'c_sp_fao') %>% 
  select(rgn_id, species, fao, Esc_c_sp_fao = Genetic.escapees) 

mar_esc <- maric %>%
  left_join(c_sp_fao, by= c("species", "fao", "rgn_id"))

data.frame(filter(mar_esc, !is.na(Esc_c_sp_fao)))
##    rgn_id         species                 fao environment year value
## 1     218 Atlantic salmon Atlantic, Northwest      Marine 1979     5
## 2     218 Atlantic salmon Atlantic, Northwest      Marine 1980    27
## 3     218 Atlantic salmon Atlantic, Northwest      Marine 1981    76
## 4     218 Atlantic salmon Atlantic, Northwest      Marine 1982   143
## 5     218 Atlantic salmon Atlantic, Northwest      Marine 1983    68
## 6     218 Atlantic salmon Atlantic, Northwest      Marine 1984   222
## 7     218 Atlantic salmon Atlantic, Northwest      Marine 1985   349
## 8     218 Atlantic salmon Atlantic, Northwest      Marine 1986   682
## 9     218 Atlantic salmon Atlantic, Northwest      Marine 1987  1382
## 10    218 Atlantic salmon  Pacific, Northeast      Marine 1987     3
## 11    218 Atlantic salmon Atlantic, Northwest      Marine 1988  3351
## 12    218 Atlantic salmon  Pacific, Northeast      Marine 1988    80
## 13    218 Atlantic salmon Atlantic, Northwest      Marine 1989  4687
## 14    218 Atlantic salmon  Pacific, Northeast      Marine 1989  1280
## 15    218 Atlantic salmon Atlantic, Northwest      Marine 1990  7835
## 16    218 Atlantic salmon  Pacific, Northeast      Marine 1990  1790
## 17    218 Atlantic salmon Atlantic, Northwest      Marine 1991  9848
## 18    218 Atlantic salmon  Pacific, Northeast      Marine 1991  3651
## 19    218 Atlantic salmon Atlantic, Northwest      Marine 1992 10520
## 20    218 Atlantic salmon  Pacific, Northeast      Marine 1992  6785
## 21    218 Atlantic salmon Atlantic, Northwest      Marine 1993 11123
## 22    218 Atlantic salmon  Pacific, Northeast      Marine 1993 12360
## 23    218 Atlantic salmon Atlantic, Northwest      Marine 1994 12426
## 24    218 Atlantic salmon  Pacific, Northeast      Marine 1994 15347
## 25    218 Atlantic salmon Atlantic, Northwest      Marine 1995 15235
## 26    218 Atlantic salmon  Pacific, Northeast      Marine 1995 18439
## 27    218 Atlantic salmon Atlantic, Northwest      Marine 1996 17800
## 28    218 Atlantic salmon  Pacific, Northeast      Marine 1996 18675
## 29    218 Atlantic salmon Atlantic, Northwest      Marine 1997 20310
## 30    218 Atlantic salmon  Pacific, Northeast      Marine 1997 30705
## 31    218 Atlantic salmon Atlantic, Northwest      Marine 1998 16418
## 32    218 Atlantic salmon  Pacific, Northeast      Marine 1998 33057
## 33    218 Atlantic salmon Atlantic, Northwest      Marine 1999 23190
## 34    218 Atlantic salmon  Pacific, Northeast      Marine 1999 38800
## 35    218 Atlantic salmon Atlantic, Northwest      Marine 2000 33195
## 36    218 Atlantic salmon  Pacific, Northeast      Marine 2000 39300
## 37    218 Atlantic salmon Atlantic, Northwest      Marine 2001 37606
## 38    218 Atlantic salmon  Pacific, Northeast      Marine 2001 58000
## 39    218 Atlantic salmon Atlantic, Northwest      Marine 2002 42121
## 40    218 Atlantic salmon  Pacific, Northeast      Marine 2002 72800
## 41    218 Atlantic salmon Atlantic, Northwest      Marine 2003 34550
## 42    218 Atlantic salmon  Pacific, Northeast      Marine 2003 72678
## 43    218 Atlantic salmon Atlantic, Northwest      Marine 2004 35000
## 44    218 Atlantic salmon  Pacific, Northeast      Marine 2004 61774
## 45    218 Atlantic salmon Atlantic, Northwest      Marine 2005 35000
## 46    218 Atlantic salmon  Pacific, Northeast      Marine 2005 63370
## 47    218 Atlantic salmon Atlantic, Northwest      Marine 2006 47880
## 48    218 Atlantic salmon  Pacific, Northeast      Marine 2006 70181
## 49    218 Atlantic salmon Atlantic, Northwest      Marine 2007 31511
## 50    218 Atlantic salmon  Pacific, Northeast      Marine 2007 70998
## 51    218 Atlantic salmon Atlantic, Northwest      Marine 2008 30810
## 52    218 Atlantic salmon  Pacific, Northeast      Marine 2008 73265
## 53    218 Atlantic salmon Atlantic, Northwest      Marine 2009 31550
## 54    218 Atlantic salmon  Pacific, Northeast      Marine 2009 68662
## 55    218 Atlantic salmon Atlantic, Northwest      Marine 2010 30713
## 56    218 Atlantic salmon  Pacific, Northeast      Marine 2010 70831
## 57    218 Atlantic salmon Atlantic, Northwest      Marine 2011 27184
## 58    218 Atlantic salmon  Pacific, Northeast      Marine 2011 83144
## 59    218 Atlantic salmon Atlantic, Northwest      Marine 2012 36120
## 60    218 Atlantic salmon  Pacific, Northeast      Marine 2012 79981
## 61    218 Atlantic salmon Atlantic, Northwest      Marine 2013 25453
## 62    218 Atlantic salmon  Pacific, Northeast      Marine 2013 74673
## 63    218 Atlantic salmon Atlantic, Northwest      Marine 2014 24008
## 64    218 Atlantic salmon  Pacific, Northeast      Marine 2014 54971
##    Taxon_code gap_0_fill species_code Esc_c_sp_fao
## 1           F          0          988          1.0
## 2           F          0          988          1.0
## 3           F          0          988          1.0
## 4           F          0          988          1.0
## 5           F          0          988          1.0
## 6           F          0          988          1.0
## 7           F          0          988          1.0
## 8           F          0          988          1.0
## 9           F          0          988          1.0
## 10          F          0          989          0.1
## 11          F          0          988          1.0
## 12          F          0          989          0.1
## 13          F          0          988          1.0
## 14          F          0          989          0.1
## 15          F          0          988          1.0
## 16          F          0          989          0.1
## 17          F          0          988          1.0
## 18          F          0          989          0.1
## 19          F          0          988          1.0
## 20          F          0          989          0.1
## 21          F          0          988          1.0
## 22          F          0          989          0.1
## 23          F          0          988          1.0
## 24          F          0          989          0.1
## 25          F          0          988          1.0
## 26          F          0          989          0.1
## 27          F          0          988          1.0
## 28          F          0          989          0.1
## 29          F          0          988          1.0
## 30          F          0          989          0.1
## 31          F          0          988          1.0
## 32          F          0          989          0.1
## 33          F          0          988          1.0
## 34          F          0          989          0.1
## 35          F          0          988          1.0
## 36          F          0          989          0.1
## 37          F          0          988          1.0
## 38          F          0          989          0.1
## 39          F          0          988          1.0
## 40          F          0          989          0.1
## 41          F          0          988          1.0
## 42          F          0          989          0.1
## 43          F          0          988          1.0
## 44          F          0          989          0.1
## 45          F          0          988          1.0
## 46          F          0          989          0.1
## 47          F          0          988          1.0
## 48          F          0          989          0.1
## 49          F          0          988          1.0
## 50          F          0          989          0.1
## 51          F          0          988          1.0
## 52          F          0          989          0.1
## 53          F          0          988          1.0
## 54          F          0          989          0.1
## 55          F          0          988          1.0
## 56          F          0          989          0.1
## 57          F          0          988          1.0
## 58          F          0          989          0.1
## 59          F          0          988          1.0
## 60          F          0          989          0.1
## 61          F          0          988          1.0
## 62          F          0          989          0.1
## 63          F          0          988          1.0
## 64          F          0          989          0.1
# join taxa specific to country/species
c_sp = esc %>% 
  filter(match_type == 'c_sp') %>% 
  select(rgn_id, species, Esc_c_sp = Genetic.escapees)

mar_esc <- mar_esc %>%
  left_join(c_sp, by= c("species", "rgn_id"))
summary(mar_esc)
##      rgn_id        species              fao            environment       
##  Min.   :  5.0   Length:25849       Length:25849       Length:25849      
##  1st Qu.: 51.0   Class :character   Class :character   Class :character  
##  Median :163.0   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :130.2                                                           
##  3rd Qu.:205.0                                                           
##  Max.   :250.0                                                           
##                                                                          
##       year          value          Taxon_code         gap_0_fill       
##  Min.   :1950   Min.   :      0   Length:25849       Length:25849      
##  1st Qu.:1990   1st Qu.:      1   Class :character   Class :character  
##  Median :2001   Median :    100   Mode  :character   Mode  :character  
##  Mean   :1997   Mean   :  17082                                        
##  3rd Qu.:2008   3rd Qu.:   1860                                        
##  Max.   :2014   Max.   :4352694                                        
##                                                                        
##   species_code     Esc_c_sp_fao      Esc_c_sp    
##  Min.   :   1.0   Min.   :0.100   Min.   :0.100  
##  1st Qu.: 241.0   1st Qu.:0.100   1st Qu.:0.500  
##  Median : 530.0   Median :1.000   Median :1.000  
##  Mean   : 528.5   Mean   :0.606   Mean   :0.739  
##  3rd Qu.: 825.0   3rd Qu.:1.000   3rd Qu.:1.000  
##  Max.   :1052.0   Max.   :1.000   Max.   :1.000  
##                   NA's   :25785   NA's   :16301
### merge these into a single sustainability score
mar_esc = mar_esc %>% 
  mutate(Escapees = ifelse(!is.na(Esc_c_sp_fao), Esc_c_sp_fao, Esc_c_sp)) %>%
  select(-Esc_c_sp_fao, -Esc_c_sp)

Join the sustainability data that is gapfilled either at the species level (average of specific species/genera across regions) or at a higher course taxonomic levels and documents which data are gapfilled and how.

## Gapfilled at the species/genera level:
gf_species_esc <- filter(esc, gapfill != "actuals" & match_type == "species") %>%
  select(species, gapfill, Esc_gf_sp = Genetic.escapees)

## check that there are no duplicated species_fao
gf_species_esc[duplicated(gf_species_esc$species), ]
## # A tibble: 0 x 3
## # ... with 3 variables: species <chr>, gapfill <chr>, Esc_gf_sp <dbl>
# Match gapfilling values by species
mar_esc_gf = mar_esc %>%
  left_join(gf_species_esc, by = 'species')


# Gapfilled at the coarse taxon level:
gf_taxon_sus <- filter(esc, gapfill != "actuals" & match_type == "taxon") %>%
  select(Taxon_code=taxon, Esc_gf_taxon = Genetic.escapees)

# Match gapfilling values by species
mar_esc_gf = mar_esc_gf %>%
  left_join(gf_taxon_sus, by = c('Taxon_code'))

summary(mar_esc_gf)
##      rgn_id        species              fao            environment       
##  Min.   :  5.0   Length:25849       Length:25849       Length:25849      
##  1st Qu.: 51.0   Class :character   Class :character   Class :character  
##  Median :163.0   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :130.2                                                           
##  3rd Qu.:205.0                                                           
##  Max.   :250.0                                                           
##                                                                          
##       year          value          Taxon_code         gap_0_fill       
##  Min.   :1950   Min.   :      0   Length:25849       Length:25849      
##  1st Qu.:1990   1st Qu.:      1   Class :character   Class :character  
##  Median :2001   Median :    100   Mode  :character   Mode  :character  
##  Mean   :1997   Mean   :  17082                                        
##  3rd Qu.:2008   3rd Qu.:   1860                                        
##  Max.   :2014   Max.   :4352694                                        
##                                                                        
##   species_code       Escapees       gapfill            Esc_gf_sp    
##  Min.   :   1.0   Min.   :0.100   Length:25849       Min.   :0.500  
##  1st Qu.: 241.0   1st Qu.:0.500   Class :character   1st Qu.:0.500  
##  Median : 530.0   Median :1.000   Mode  :character   Median :0.625  
##  Mean   : 528.5   Mean   :0.738                      Mean   :0.678  
##  3rd Qu.: 825.0   3rd Qu.:1.000                      3rd Qu.:0.797  
##  Max.   :1052.0   Max.   :1.000                      Max.   :0.925  
##                   NA's   :16237                      NA's   :23672  
##   Esc_gf_taxon   
##  Min.   :0.1000  
##  1st Qu.:0.7423  
##  Median :0.7423  
##  Mean   :0.7042  
##  3rd Qu.:0.7664  
##  Max.   :0.7664  
## 
table(mar_esc_gf$gapfill)
## 
## genus_average 
##          2177
#Obtain a sustainability score for each record, and a book-keeping column of whether it's actual or gap-filled
tonnes_esc = mar_esc_gf %>% 
  mutate(gapfill = ifelse(!is.na(Escapees), "none", gapfill)) %>% 
  mutate(Escapees = ifelse(is.na(Escapees), Esc_gf_sp, Escapees)) %>%
  mutate(gapfill = ifelse(is.na(Escapees), "taxon_average", gapfill)) %>%
  mutate(Escapees = ifelse(is.na(Escapees), Esc_gf_taxon, Escapees)) %>%
  select(rgn_id, species, species_code, year, gapfill_escapees = gapfill, tonnes=value, Escapees)

summary(tonnes_esc)
##      rgn_id        species           species_code         year     
##  Min.   :  5.0   Length:25849       Min.   :   1.0   Min.   :1950  
##  1st Qu.: 51.0   Class :character   1st Qu.: 241.0   1st Qu.:1990  
##  Median :163.0   Mode  :character   Median : 530.0   Median :2001  
##  Mean   :130.2                      Mean   : 528.5   Mean   :1997  
##  3rd Qu.:205.0                      3rd Qu.: 825.0   3rd Qu.:2008  
##  Max.   :250.0                      Max.   :1052.0   Max.   :2014  
##  gapfill_escapees       tonnes           Escapees     
##  Length:25849       Min.   :      0   Min.   :0.1000  
##  Class :character   1st Qu.:      1   1st Qu.:0.5807  
##  Mode  :character   Median :    100   Median :0.7664  
##                     Mean   :  17082   Mean   :0.7092  
##                     3rd Qu.:   1860   3rd Qu.:0.9000  
##                     Max.   :4352694   Max.   :1.0000

Final formatting of the escapee data. This is used as a pressure layer.

# for each region/year: average the genetic escape probability for each taxa based on tonnes mariculture
genEscapes <- tonnes_esc %>%
  group_by(rgn_id, year) %>%
  summarize(genEscapes = weighted.mean(Escapees, tonnes, na.rm=TRUE))

# obtain corresponding gapfilling information for each region (average of gapfilled data, weighted by tonnes of mariculture).
genEscapes_gf <- tonnes_esc %>%
  mutate(gapfill = ifelse(gapfill_escapees=="none", 1, 0)) %>%
  group_by(rgn_id, year) %>%
  summarize(genEscapes = weighted.mean(gapfill, tonnes, na.rm=TRUE)) %>%
  ungroup() %>%
  filter(year==2014) %>%
  select(rgn_id, pressures.score=genEscapes) %>%
  mutate(pressures.score=ifelse(pressures.score=="NaN", NA, pressures.score)) %>%
  data.frame()
write.csv(genEscapes_gf, 'output/GenEsc_v2016_gf.csv', row.names=FALSE)

# create the escapee data layers:
for(year in 2012:2016){ #year=2016
data_year <- year-2
    data <- genEscapes %>%
    filter(year == data_year) %>%
    select(rgn_id, pressure_score = genEscapes)
write.csv(data, sprintf('output/GenEsc_v%s.csv', year), row.names=FALSE)  
}