Created
November 9, 2016 11:03
-
-
Save slarge/c998bd224360f749184851a08e6fff22 to your computer and use it in GitHub Desktop.
Takes ICES catch statistics and aggregates according to ICES area and species.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm(list = ls()) | |
# | |
library(dplyr, quietly = TRUE) | |
library(reshape2, quietly = TRUE) | |
library(ggplot2, quietly = TRUE) | |
# | |
options(scipen = 5) | |
# | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # | |
# DATA SOURCE: ICES official catch statistics (2006-2014) # | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # | |
catchURL <- "http://ices.dk/marine-data/Documents/CatchStats/OfficialNominalCatches.zip" | |
tmpFileCatch <- tempfile(fileext = ".zip") | |
download.file(catchURL, destfile = tmpFileCatch, mode = "wb", quiet = TRUE) | |
catchDat2010 <- read.csv(unz(tmpFileCatch, | |
"ICESCatchDataset2006-2014.csv"), | |
stringsAsFactors = FALSE, header = TRUE, fill = TRUE) | |
#(NOTE: this file was created manually - with stock list database this should not be necessary - SL) | |
areaDat <- read.csv("~/git/ices-dk/fisheryO/inst/extdata/areaList.csv", | |
stringsAsFactors = FALSE) | |
# | |
# Clean up the area data. n.b., there is more to this list than necessary, also has ecoregions, STECF and historical areas. | |
areaID <- areaDat %>% | |
filter(areaType %in% c("ICESarea"), | |
FO2016 == TRUE) %>% | |
select(-ICESarea, | |
-areaType, | |
-FO2016, | |
-Ecoregion) %>% | |
mutate(value = tolower(value), | |
value = gsub("_nk", "_NK", value)) | |
# Pick out the areas that you want to look at | |
head(areaID) | |
areaID <- areaID %>% | |
filter(value %in% c("27.6_NK", "27.7.c_NK")) # ... and whatever else you want to see. | |
# | |
catchDat2010Clean <- catchDat2010 %>% | |
Filter(f = function(x)!all(is.na(x))) %>% # Get rid of extra columns of NA | |
select(-Units, | |
ICES_Area = Area) %>% | |
melt(id.vars = c("Species", "ICES_Area", "Country"), # Turn into a long data frame | |
variable.name = "YEAR", | |
value.name = "VALUE") %>% | |
mutate(YEAR = as.numeric(gsub("X", "", YEAR)), # Clean up year column | |
VALUE = as.numeric(VALUE)) %>% | |
filter(ICES_Area %in% areaID$value, | |
Species %in% c("HER", "POS", "MAC")) %>% | |
group_by(YEAR, ICES_Area, Species) %>% | |
summarize(VALUE = sum(VALUE)) | |
ggplot(catchDat2010Clean, aes(x=YEAR, y = VALUE)) + | |
geom_area(aes(fill = Species)) + | |
facet_wrap(~ICES_Area) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment