Answer the following questions and complete the exercises in
RMarkdown. Please embed all of your code and push your final work to
your repository. Your final lab report should be organized, clean, and
run free from errors. Remember, you must remove the #
for
the included code chunks to run. Be sure to add your name to the author
header above.
Make sure to use the formatting conventions of RMarkdown to make your report neat and clean!
library(tidyverse)
For this assignment we are going to work with a data set from the United Nations Food and Agriculture Organization on world fisheries.
Load the data fisheries.csv
as a new object titled
fisheries
.
fisheries <- read_csv("data/fisheries.csv")
## Rows: 376771 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (6): country, common_name, isscaap_taxonomic_group, asfis_species_number...
## dbl (4): isscaap_group_number, fao_major_fishing_area, year, catch
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
glimpse(fisheries)
## Rows: 376,771
## Columns: 10
## $ country <chr> "Albania", "Albania", "Albania", "Albania", "A…
## $ common_name <chr> "Angelsharks, sand devils nei", "Angelsharks, …
## $ isscaap_group_number <dbl> 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38…
## $ isscaap_taxonomic_group <chr> "Sharks, rays, chimaeras", "Sharks, rays, chim…
## $ asfis_species_number <chr> "10903XXXXX", "10903XXXXX", "10903XXXXX", "109…
## $ asfis_species_name <chr> "Squatinidae", "Squatinidae", "Squatinidae", "…
## $ fao_major_fishing_area <dbl> 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37…
## $ measure <chr> "Quantity (tonnes)", "Quantity (tonnes)", "Qua…
## $ year <dbl> 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002…
## $ catch <dbl> NA, 53, 20, 31, 30, 30, 16, 79, 1, 4, 68, 55, …
fisheries %>%
summarize(n_countries = n_distinct(country))
## # A tibble: 1 × 1
## n_countries
## <int>
## 1 203
fisheries$country %>% unique()
## [1] "Albania" "Algeria"
## [3] "American Samoa" "Angola"
## [5] "Anguilla" "Antigua and Barbuda"
## [7] "Argentina" "Aruba"
## [9] "Australia" "Bahamas"
## [11] "Bahrain" "Bangladesh"
## [13] "Barbados" "Belgium"
## [15] "Belize" "Benin"
## [17] "Bermuda" "Bonaire/S.Eustatius/Saba"
## [19] "Bosnia and Herzegovina" "Brazil"
## [21] "British Indian Ocean Ter" "British Virgin Islands"
## [23] "Brunei Darussalam" "Bulgaria"
## [25] "Cabo Verde" "Cambodia"
## [27] "Cameroon" "Canada"
## [29] "Cayman Islands" "Channel Islands"
## [31] "Chile" "China"
## [33] "China, Hong Kong SAR" "China, Macao SAR"
## [35] "Colombia" "Comoros"
## [37] "Congo, Dem. Rep. of the" "Congo, Republic of"
## [39] "Cook Islands" "Costa Rica"
## [41] "Croatia" "Cuba"
## [43] "Cura\xe7ao" "Cyprus"
## [45] "C\xf4te d'Ivoire" "Denmark"
## [47] "Djibouti" "Dominica"
## [49] "Dominican Republic" "Ecuador"
## [51] "Egypt" "El Salvador"
## [53] "Equatorial Guinea" "Eritrea"
## [55] "Estonia" "Ethiopia"
## [57] "Falkland Is.(Malvinas)" "Faroe Islands"
## [59] "Fiji, Republic of" "Finland"
## [61] "France" "French Guiana"
## [63] "French Polynesia" "French Southern Terr"
## [65] "Gabon" "Gambia"
## [67] "Georgia" "Germany"
## [69] "Ghana" "Gibraltar"
## [71] "Greece" "Greenland"
## [73] "Grenada" "Guadeloupe"
## [75] "Guam" "Guatemala"
## [77] "Guinea" "GuineaBissau"
## [79] "Guyana" "Haiti"
## [81] "Honduras" "Iceland"
## [83] "India" "Indonesia"
## [85] "Iran (Islamic Rep. of)" "Iraq"
## [87] "Ireland" "Isle of Man"
## [89] "Israel" "Italy"
## [91] "Jamaica" "Japan"
## [93] "Jordan" "Kenya"
## [95] "Kiribati" "Korea, Dem. People's Rep"
## [97] "Korea, Republic of" "Kuwait"
## [99] "Latvia" "Lebanon"
## [101] "Liberia" "Libya"
## [103] "Lithuania" "Madagascar"
## [105] "Malaysia" "Maldives"
## [107] "Malta" "Marshall Islands"
## [109] "Martinique" "Mauritania"
## [111] "Mauritius" "Mayotte"
## [113] "Mexico" "Micronesia, Fed.States of"
## [115] "Monaco" "Montenegro"
## [117] "Montserrat" "Morocco"
## [119] "Mozambique" "Myanmar"
## [121] "Namibia" "Nauru"
## [123] "Netherlands" "Netherlands Antilles"
## [125] "New Caledonia" "New Zealand"
## [127] "Nicaragua" "Nigeria"
## [129] "Niue" "Norfolk Island"
## [131] "Northern Mariana Is." "Norway"
## [133] "Oman" "Other nei"
## [135] "Pakistan" "Palau"
## [137] "Palestine, Occupied Tr." "Panama"
## [139] "Papua New Guinea" "Peru"
## [141] "Philippines" "Pitcairn Islands"
## [143] "Poland" "Portugal"
## [145] "Puerto Rico" "Qatar"
## [147] "Romania" "Russian Federation"
## [149] "R\xe9union" "Saint Barth\xe9lemy"
## [151] "Saint Helena" "Saint Kitts and Nevis"
## [153] "Saint Lucia" "Saint Vincent/Grenadines"
## [155] "SaintMartin" "Samoa"
## [157] "Sao Tome and Principe" "Saudi Arabia"
## [159] "Senegal" "Serbia and Montenegro"
## [161] "Seychelles" "Sierra Leone"
## [163] "Singapore" "Sint Maarten"
## [165] "Slovenia" "Solomon Islands"
## [167] "Somalia" "South Africa"
## [169] "Spain" "Sri Lanka"
## [171] "St. Pierre and Miquelon" "Sudan"
## [173] "Sudan (former)" "Suriname"
## [175] "Svalbard and Jan Mayen" "Sweden"
## [177] "Syrian Arab Republic" "Taiwan Province of China"
## [179] "Tanzania, United Rep. of" "Thailand"
## [181] "TimorLeste" "Togo"
## [183] "Tokelau" "Tonga"
## [185] "Trinidad and Tobago" "Tunisia"
## [187] "Turkey" "Turks and Caicos Is."
## [189] "Tuvalu" "US Virgin Islands"
## [191] "Ukraine" "Un. Sov. Soc. Rep."
## [193] "United Arab Emirates" "United Kingdom"
## [195] "United States of America" "Uruguay"
## [197] "Vanuatu" "Venezuela, Boliv Rep of"
## [199] "Viet Nam" "Wallis and Futuna Is."
## [201] "Yemen" "Yugoslavia SFR"
## [203] "Zanzibar"
asfis_species_number
, how many different
(i.e.) fish species were caught?fisheries%>%
mutate(asfis_species_number=as.factor(asfis_species_number)) %>%
summarize(n_taxa=n_distinct(asfis_species_number))
## # A tibble: 1 × 1
## n_taxa
## <int>
## 1 1551
isscaap_taxonomic_group
in the data set?fisheries %>%
group_by(isscaap_taxonomic_group) %>%
summarize(total_catch=sum(catch, na.rm=T)) %>%
arrange(desc(total_catch))
## # A tibble: 30 × 2
## isscaap_taxonomic_group total_catch
## <chr> <dbl>
## 1 Herrings, sardines, anchovies 1898529
## 2 Cods, hakes, haddocks 1218092
## 3 Miscellaneous pelagic fishes 1217644
## 4 Miscellaneous coastal fishes 995248
## 5 Tunas, bonitos, billfishes 978951
## 6 Marine fishes not identified 863949
## 7 Miscellaneous demersal fishes 452445
## 8 Squids, cuttlefishes, octopuses 311928
## 9 Sharks, rays, chimaeras 263569
## 10 Shrimps, prawns 228203
## # ℹ 20 more rows
asfis_species_name
, what are the top 5
most caught species? (note: “Osteichthyes” is not a species, it refers
to unidentified fish. You should filter this one out.).fisheries %>%
filter(asfis_species_name != "Osteichthyes") %>%
group_by(asfis_species_number, asfis_species_name) %>%
summarize(total_catch=sum(catch, na.rm=T), .groups='keep') %>%
arrange(-total_catch)
## # A tibble: 1,547 × 3
## # Groups: asfis_species_number, asfis_species_name [1,547]
## asfis_species_number asfis_species_name total_catch
## <chr> <chr> <dbl>
## 1 1210600208 Engraulis ringens 540739
## 2 1480401601 Theragra chalcogramma 473722
## 3 1210500105 Clupea harengus 264304
## 4 1480400202 Gadus morhua 217930
## 5 1750102501 Katsuwonus pelamis 194923
## 6 1210501303 Sardinops sagax 176094
## 7 1750100201 Scomber japonicus 175444
## 8 1702300405 Trachurus murphyi 152034
## 9 1210501301 Sardinops melanostictus 144774
## 10 1230400201 Mallotus villosus 131239
## # ℹ 1,537 more rows
fisheries %>%
filter(asfis_species_name == "Engraulis ringens") %>%
group_by(country) %>%
summarize(catch_total=sum(catch, na.rm=T)) %>%
arrange(desc(catch_total))
## # A tibble: 3 × 2
## country catch_total
## <chr> <dbl>
## 1 Peru 439717
## 2 Chile 100694
## 3 Ecuador 328
fisheries%>%
filter(year>=2002 & year<=2012) %>%
group_by(country) %>%
summarize(catch_total=sum(catch, na.rm=T)) %>%
arrange(desc(catch_total))
## # A tibble: 200 × 2
## country catch_total
## <chr> <dbl>
## 1 China 269238
## 2 United States of America 167309
## 3 Russian Federation 112028
## 4 Indonesia 104362
## 5 Japan 104152
## 6 Chile 97030
## 7 Spain 92286
## 8 Peru 86482
## 9 Portugal 69778
## 10 India 69681
## # ℹ 190 more rows
fisheries %>%
group_by(country, year) %>%
summarize(catch_total=sum(catch, na.rm=T), .groups = 'keep') %>%
arrange(desc(catch_total))
## # A tibble: 11,583 × 3
## # Groups: country, year [11,583]
## country year catch_total
## <chr> <dbl> <dbl>
## 1 Peru 1970 77000
## 2 Peru 1971 76800
## 3 Peru 1968 62700
## 4 China 2001 39327
## 5 Japan 1972 30167
## 6 Japan 1988 29701
## 7 China 2002 28967
## 8 China 2010 27851
## 9 Japan 1976 27825
## 10 China 1998 27593
## # ℹ 11,573 more rows
sharks
that only
contains data on this group.sharks <- fisheries %>%
filter(isscaap_taxonomic_group == "Sharks, rays, chimaeras")
sharks
dataframe, use mutate()
to create a new column called fishing_pressure
that is
based on the total catch. If the total catch is greater than 75, the
fishing pressure is considered “high”, otherwise it is considered
“moderate”.sharks <- sharks %>%
mutate(fishing_pressure=ifelse(catch>75, "high", "moderate"))
sharks %>%
filter(catch>0 | catch!="NA") %>%
group_by(fishing_pressure) %>%
summarize(avg_catch=mean(catch, na.rm=T))
## # A tibble: 2 × 2
## fishing_pressure avg_catch
## <chr> <dbl>
## 1 high 86.6
## 2 moderate 14.3
Please be sure that you check the keep md
file in the
knit preferences.