Content
I’m interested in fishery management and ocean conservation, particulary related to ecologically sensitive species such as sharks and rays. Currently I’m working in the Fisheries Management group for the Informatics course at the Master of Environmental Science and Management at UCSB.
Techniques
I hope to take from the Informatics course skills like how use the github plataform, that allows a collaborative workspace, and how to organize and manage data. Also, I think improving my R skills, especially in generating better visualitions of data, might be a differential in my future professional life.
Data
At the present moment I’m not participating in any MESM project. However, when searching for a opportunity to write my proposal I looked at The International Comission for the Conservation of Atlantic Tunas (ICCAT) database on shark captures, which I’ll be using for this assignment.
# read csv
d = read.csv('data/caio-faro_ICCATSharks.csv')
Brazil <- subset(d, PartyName == "BRAZIL")
summary(Brazil)
## Species ScieName SpeciesGrp
## BSH :211 Prionace glauca :211 4-Sharks (major):403
## SMA :191 Isurus oxyrinchus :191 5-Sharks (other):821
## SPN :133 Sphyrna spp :133
## BTH :130 Alopias superciliosus:130
## SHX : 92 Squaliformes : 92
## RSK : 85 Carcharhinidae : 85
## (Other):382 (Other) :382
## YearC Decade Status PartyName Flag
## Min. :1994 Min. :1990 CP :1224 BRAZIL :1224 Brazil :1224
## 1st Qu.:2003 1st Qu.:2000 NCC: 0 ALGÉRIE : 0 Algerie : 0
## Median :2005 Median :2000 NCO: 0 ANGOLA : 0 Angola : 0
## Mean :2006 Mean :2002 BARBADOS: 0 Argentina: 0
## 3rd Qu.:2009 3rd Qu.:2000 BELIZE : 0 Barbados : 0
## Max. :2014 Max. :2010 CANADA : 0 Belize : 0
## (Other) : 0 (Other) : 0
## Fleet Stock SampArea AreaT1
## BRA-BRA-ITAJAI :138 A+M:821 unkn :1213 SW :1206
## BRA-BRA-NATAL :114 ATN: 6 BIL96 : 11 NW : 17
## BRA-BRA-RJANERO: 92 ATS:397 BIL91 : 0 GOFM : 1
## BRA : 67 MED: 0 BIL92 : 0 ATL : 0
## BRA-BRA-SANTOS : 64 BIL93 : 0 AZOR : 0
## BRA-ESP-NATAL : 60 BIL94 : 0 BLACK : 0
## (Other) :689 (Other): 0 (Other): 0
## SpcGearGrp GearGrp GearCode CatchTypeCode
## All gears :822 LL :998 LL :839 C :977
## Longline :330 UN : 77 LLFB :137 DD: 13
## Other surf.: 72 BB : 46 UNCL : 77 L :234
## SU : 36 BB : 46
## HL : 35 SURF : 36
## PS : 19 HAND : 35
## (Other): 13 (Other): 54
## QualInfoCode Qty_t
## RPT1 :1158 Min. : 0.000
## UNKN : 47 1st Qu.: 0.300
## RCSP : 19 Median : 3.366
## OBSH : 0 Mean : 56.081
## RCAR : 0 3rd Qu.: 21.776
## RCGR : 0 Max. :2609.500
## (Other): 0
Data Wrangling
suppressWarnings(suppressMessages(require(readr)))
suppressWarnings(suppressMessages(require(dplyr)))
tbl_df(Brazil)
## Source: local data frame [1,224 x 18]
##
## Species ScieName SpeciesGrp YearC Decade Status
## (fctr) (fctr) (fctr) (int) (int) (fctr)
## 1 BSH Prionace glauca 4-Sharks (major) 2002 2000 CP
## 2 SMA Isurus oxyrinchus 4-Sharks (major) 2002 2000 CP
## 3 SHX Squaliformes 5-Sharks (other) 2002 2000 CP
## 4 BSH Prionace glauca 4-Sharks (major) 2002 2000 CP
## 5 FAL Carcharhinus falciformis 5-Sharks (other) 2002 2000 CP
## 6 BTH Alopias superciliosus 5-Sharks (other) 2002 2000 CP
## 7 SMA Isurus oxyrinchus 4-Sharks (major) 2002 2000 CP
## 8 SHX Squaliformes 5-Sharks (other) 2002 2000 CP
## 9 BSH Prionace glauca 4-Sharks (major) 2002 2000 CP
## 10 FAL Carcharhinus falciformis 5-Sharks (other) 2002 2000 CP
## .. ... ... ... ... ... ...
## Variables not shown: PartyName (fctr), Flag (fctr), Fleet (fctr), Stock
## (fctr), SampArea (fctr), AreaT1 (fctr), SpcGearGrp (fctr), GearGrp
## (fctr), GearCode (fctr), CatchTypeCode (fctr), QualInfoCode (fctr),
## Qty_t (dbl)
Brazil %>%
select(ScieName, YearC, Status, Fleet, Stock, GearCode, Qty_t) %>%
group_by(ScieName) %>%
summarize(Total_Catch_t = sum(Qty_t))
## Source: local data frame [27 x 2]
##
## ScieName Total_Catch_t
## (fctr) (dbl)
## 1 Alopias spp 148.827000
## 2 Alopias superciliosus 747.963952
## 3 Carcharhinidae 1600.884882
## 4 Carcharhiniformes 6132.138284
## 5 Carcharhinus falciformis 1811.366600
## 6 Carcharhinus leucas 8.237015
## 7 Carcharhinus longimanus 2155.981042
## 8 Carcharhinus signatus 23.374000
## 9 Carcharias taurus 9.272000
## 10 Coastal Sharks nei 411.040000
## .. ... ...
4. Answers and Taks
Task. Convert the following table CO2 emissions per country since 1970 from wide to long format and output the first few rows into your Rmarkdown. I recommend consulting ?gather
and you should have 3 columns in your output.
library(dplyr)
library(readxl) # install.packages('readxl')
# xls downloaded from http://edgar.jrc.ec.europa.eu/news_docs/CO2_1970-2014_dataset_of_CO2_report_2015.xls
xls = '../data/co2_europa.xls'
require(tidyr)
require(dplyr)
print(getwd())
co2 <- read_excel(xls, skip=12)
Longco2 <- gather(co2, "Year", "Emissions", -Country) %>%
mutate(Year = as.numeric(Year))
head(Longco2)
Question. Why use skip=12
argument in read_excel()
? Because the first 12 rows are metadata and we skip them to read only the data from the table we’re gonna use.
Task. Report the top 5 emitting countries (not World or EU28) for 2014 using your long format table. (You may need to convert your year column from factor to numeric, eg mutate(year = as.numeric(as.character(year)))
. As with most analyses, there are multiple ways to do this. I used the following functions: filter
, arrange
, desc
, head
).
Top5 <- Longco2 %>%
filter(Year == 2014, Country != "World", Country != "EU28") %>%
arrange(desc(Emissions))
head(Top5, n=5)
Task. Summarize the total emissions by country (not World or EU28) across years from your long format table and return the top 5 emitting countries. (As with most analyses, there are multiple ways to do this. I used the following functions: filter
, arrange
, desc
, head
).
SumCountries <- Longco2 %>%
filter(Country != "World", Country != "EU28") %>%
group_by(Country) %>%
summarise(TotalEmission = sum(Emissions)) %>%
arrange(desc(TotalEmission))
head(SumCountries)