data retrieved by Dr. Einar of Iceland from FAO website. He is having full code of data retrieve from the website.
0.2 Call the R libraries
library(tidyverse)
Warning: package 'ggplot2' was built under R version 4.3.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(plotly)
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
library("ggplot2")library(gridExtra)
Attaching package: 'gridExtra'
The following object is masked from 'package:dplyr':
combine
Rows: 66673 Columns: 9
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (6): country, species, measure, sid, latin, country_iso3
dbl (3): 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.
x=fao|>distinct(country)x
# A tibble: 61 × 1
country
<chr>
1 Anguilla
2 Antigua and Barbuda
3 Aruba
4 Bahamas
5 Barbados
6 Belize
7 Bermuda
8 Bonaire/S.Eustatius/Saba
9 Brazil
10 British Virgin Islands
# ℹ 51 more rows
0.4 Country wise production trend in CRFM member countries
y= fao|>filter(country %in%c("Barbados","Belize","Anguilla", "Antigua and Barbuda", "Bahamas", "Dominica", "Grenada", "Guyana", "Haiti", "Jamaica", "Montserrat", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent/Grenadines", "Suriname", "Trinidad and Tobago", "Turks and Caicos Is."))|>group_by(country, year)|>summarise(catch=sum(catch))|>ggplot(aes(year, catch))+geom_col(fill="steelblue")+facet_wrap(~ country, scales="free_y", ncol =3)
`summarise()` has grouped output by 'country'. You can override using the
`.groups` argument.
ggplotly(y)
The 17 member countries are defined and the data was extracted from the FAO data set stored in Iceland website
1 Flying fish catch trend
p1 = fao|>filter(country %in%c("Barbados","Belize","Anguilla", "Antigua and Barbuda", "Bahamas", "Dominica", "Grenada", "Guyana", "Haiti", "Jamaica", "Montserrat", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent/Grenadines", "Suriname", "Trinidad and Tobago", "Turks and Caicos Is.")) |>group_by(year)|>filter(str_starts(species, "Fly")) |>select(year, species, catch)|>summarise(catch=sum(catch))|>ggplot(aes(year, catch))+geom_line(colour="blue")+geom_smooth(colour="black")+ggtitle("Flying fish") +theme_classic() +labs(y =" Catch in tons", x ="Year") +theme(axis.text =element_text(face="bold"))ggplotly(p1)
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
1.1 Lobster catch trend
p2 = fao|>filter(country %in%c("Barbados","Belize","Anguilla", "Antigua and Barbuda", "Bahamas", "Dominica", "Grenada", "Guyana", "Haiti", "Jamaica", "Montserrat", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent/Grenadines", "Suriname", "Trinidad and Tobago", "Turks and Caicos Is." ))|>group_by(year)|>filter(grepl("lobster", species)) |>select(year, species, catch)|>summarise(catch=sum(catch))|>ggplot(aes(year, catch))+geom_line(colour="blue")+geom_smooth(colour="black")+ggtitle("Lobster") +theme_classic()+labs(y =" Catch in tons", x ="Year") +theme(axis.text =element_text(face="bold"))ggplotly(p2)
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
1.2 Conch catch trend
p3=fao|>filter(country %in%c("Barbados","Belize","Anguilla", "Antigua and Barbuda", "Bahamas", "Dominica", "Grenada", "Guyana", "Haiti", "Jamaica", "Montserrat", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent/Grenadines", "Suriname", "Trinidad and Tobago", "Turks and Caicos Is." ))|>group_by(year)|>filter(grepl("conch", species)) |>select(year, species, catch)|>summarise(catch=sum(catch))|>ggplot(aes(year, catch))+geom_line(colour="blue")+geom_smooth(colour="black")+ggtitle("Conch") +theme_classic()+labs(y =" Catch in tons", x ="Year") +theme(axis.text =element_text(face="bold"))ggplotly(p3)
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
1.3 Dolphinfish catch trend
p4=fao|>filter(country %in%c("Barbados","Belize","Anguilla", "Antigua and Barbuda", "Bahamas", "Dominica", "Grenada", "Guyana", "Haiti", "Jamaica", "Montserrat", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent/Grenadines", "Suriname", "Trinidad and Tobago", "Turks and Caicos Is." ))|>group_by(year)|>filter(grepl("dolphinfish", species)) |>select(year, species, catch)|>summarise(catch=sum(catch))|>ggplot(aes(year, catch))+geom_line(colour="blue")+geom_smooth(colour="black")+ggtitle("Dolphin fish") +theme_classic()+labs(y =" Catch in tons", x ="Year") +theme(axis.text =element_text(face="bold"))ggplotly(p4)
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
2 Yellowfin tuna catch trend
p5 = fao|>filter(country %in%c("Barbados","Belize","Anguilla", "Antigua and Barbuda", "Bahamas", "Dominica", "Grenada", "Guyana", "Haiti", "Jamaica", "Montserrat", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent/Grenadines", "Suriname", "Trinidad and Tobago", "Turks and Caicos Is." ))|>group_by(year)|>filter(grepl("Yellowfin tuna", species)) |>select(year, species, catch)|>summarise(catch=sum(catch))|>ggplot(aes(year, catch))+geom_line(colour="blue")+geom_smooth(colour="black")+ggtitle("Yellow-fin tuna") +theme_classic()+labs(y =" Catch in tons", x ="Year") +theme(axis.text =element_text(face="bold"))ggplotly(p5)
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
2.2.1 Save the plot
To save the plot just save the code as a name and use the following code