Skip to content

Commit

Permalink
Update plots
Browse files Browse the repository at this point in the history
  • Loading branch information
langbart committed Jan 12, 2024
1 parent c2ba5ca commit 7530c92
Show file tree
Hide file tree
Showing 23 changed files with 132 additions and 106 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/distribution.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ <h2><span class="header-section-number">4.1</span> Fish groups<a href="distribut
</p>
</div>
<div class="figure"><span style="display:block;" id="fig:unnamed-chunk-3"></span>
<img src="Timor-nutrient-sensitive-fisheries-management_files/figure-html/unnamed-chunk-3-1.png" alt="Distribution of nutritional content among different fish groups. This series of bar graphs delineates the contribution of various fish groups to the total nutrient stock, highlighting the top ten fish groups for calcium, omega-3, iron, protein, vitamin A, and zinc. Each graph is ordered to reflect the descending contribution of each fish group relative to each nutrient." width="80%" />
<img src="Timor-nutrient-sensitive-fisheries-management_files/figure-html/unnamed-chunk-3-1.png" alt="Distribution of nutritional content among different functional fish groups: Small pelagics, Large pelagics, Small demersals, Large demersals, Sharks and rays and Other groups, that includes shrimps, molluscs, cephalopods and crustaceans. The plot shows the ranked contribution of each functional fish to the supply of calcium, omega-3, iron, protein, vitamin A, and zinc during the period 2018-2023." width="80%" />
<p class="caption">
Figure 4.2: Distribution of nutritional content among different fish groups. This series of bar graphs delineates the contribution of various fish groups to the total nutrient stock, highlighting the top ten fish groups for calcium, omega-3, iron, protein, vitamin A, and zinc. Each graph is ordered to reflect the descending contribution of each fish group relative to each nutrient.
Figure 4.2: Distribution of nutritional content among different functional fish groups: Small pelagics, Large pelagics, Small demersals, Large demersals, Sharks and rays and Other groups, that includes shrimps, molluscs, cephalopods and crustaceans. The plot shows the ranked contribution of each functional fish to the supply of calcium, omega-3, iron, protein, vitamin A, and zinc during the period 2018-2023.
</p>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/highlight.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ <h1>
<div id="header">
<h1 class="title">Modelling scenarios for nutrient-sensitive fisheries management</h1>
<p class="author"><em>Lorenzo Longobardi</em></p>
<p class="date"><em>Last update: 2024-01-11</em></p>
<p class="date"><em>Last update: 2024-01-12</em></p>
</div>
<div id="content" class="section level1 hasAnchor" number="1">
<h1><span class="header-section-number">1</span> Content<a href="index.html#content" class="anchor-section" aria-label="Anchor link to header"></a></h1>
Expand Down
12 changes: 6 additions & 6 deletions docs/profiles.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/search_index.json

Large diffs are not rendered by default.

191 changes: 103 additions & 88 deletions docs_book/03-nutrients_distribution.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ This section presents the analyses that illustrates the distribution of nutrient
## Fish groups

```{r echo=FALSE, fig.height=8, fig.width=7, message=FALSE, warning=FALSE, out.width='80%', fig.cap="The bar chart illustrates the contribution of a variety of marine food sources to the Recommended Nutrient Intake (RNI) for six fundamental nutrients, based on a 100g portion. Each bar is a color-segmented stacked visual, with distinct hues corresponding to individual nutrients, and white numbers within indicating the specific percentage contribution of each nutrient. The chart incorporates the mean annual catch in metric tons for each marine species from 2018 to 2023, presented at the end of each bar, providing a view of both the nutritional value and the harvest volume of these essential food sources. The transparency of these values is adjusted to reflect each species' relative contribution to the mean annual catch"}
library(ggplot2)
library(ggforce)
Expand All @@ -18,11 +17,11 @@ catch_groups_name <-
tot_catch <-
timor.nutrients::region_stats %>%
dplyr::mutate(year = lubridate::year(date_bin_start)) %>%
dplyr::mutate(year = lubridate::year(date_bin_start)) %>%
dplyr::group_by(grouped_taxa, year) %>%
dplyr::summarise(catch = sum(catch)) %>%
dplyr::group_by(grouped_taxa) %>%
dplyr::summarise(catch = mean(catch)) %>%
dplyr::summarise(catch = mean(catch)) %>%
dplyr::left_join(catch_groups_name) %>%
dplyr::select(-grouped_taxa) %>%
dplyr::select(catch_name, catch) %>%
Expand All @@ -49,7 +48,7 @@ base_plot <-
dplyr::mutate(tot = sum(rdi, na.rm = T)) %>%
dplyr::arrange(-tot) %>%
dplyr::left_join(tot_catch) %>%
tidyr::replace_na(list(catch = 0)) %>%
tidyr::replace_na(list(catch = 0)) %>%
dplyr::arrange(dplyr::desc(nutrient))
tot_catch_plot <-
Expand Down Expand Up @@ -91,34 +90,48 @@ ggplot2::ggplot() +
ggplot2::scale_color_manual(values = timor.nutrients::palettes$nutrients_palette) +
ggplot2::scale_y_continuous(labels = scales::percent, n.breaks = 10) +
ggplot2::labs(x = "", y = "Matched RNI from 100g portion", fill = "") +
ggplot2::theme(legend.position = "bottom",
panel.grid.minor = element_blank()) +
coord_flip(expand = FALSE, ylim = c(0, 1.55)) +
ggplot2::theme(
legend.position = "bottom",
panel.grid.minor = element_blank()
) +
coord_flip(expand = FALSE, ylim = c(0, 1.55)) +
guides(
alpha = "none",
color = "none"
)
```


```{r echo=FALSE, fig.height=8, fig.width=7, message=FALSE, warning=FALSE, out.width='80%', fig.cap="Distribution of nutritional content among different fish groups. This series of bar graphs delineates the contribution of various fish groups to the total nutrient stock, highlighting the top ten fish groups for calcium, omega-3, iron, protein, vitamin A, and zinc. Each graph is ordered to reflect the descending contribution of each fish group relative to each nutrient."}
```{r echo=FALSE, fig.height=7, fig.width=7, message=FALSE, warning=FALSE, out.width='80%', fig.cap="Distribution of nutritional content among different functional fish groups: Small pelagics, Large pelagics, Small demersals, Large demersals, Sharks and rays and Other groups, that includes shrimps, molluscs, cephalopods and crustaceans. The plot shows the ranked contribution of each functional fish to the supply of calcium, omega-3, iron, protein, vitamin A, and zinc during the period 2018-2023."}
timor.nutrients::region_stats %>%
dplyr::group_by(grouped_taxa) %>%
dplyr::mutate(fish_group = dplyr::case_when(
grouped_taxa %in% c("COZ") ~ "Molluscs",
grouped_taxa %in% c("PEZ") ~ "Shrimps",
grouped_taxa %in% c("MZZ") ~ "Other",
grouped_taxa %in% c("SLV", "CRA") ~ "Crustaceans",
grouped_taxa %in% c("OCZ", "IAX") ~ "Cephalopods",
grouped_taxa %in% c("SKH", "SRX") ~ "Sharks and rays",
grouped_taxa %in% c("SNA", "GPX", "PWT", "GRX", "MUI", "BGX") ~ "Large demersals",
grouped_taxa %in% c("CGX", "TUN", "BEN", "LWX", "BAR", "SFA", "CBA", "DOX", "ECN", "DOS") ~ "Large pelagics",
grouped_taxa %in% c("YDX", "SPI", "EMP", "SUR", "TRI", "MOJ", "WRA", "MOO", "BWH", "LGE", "MOB", "MHL", "GOX", "THO", "IHX", "APO", "IHX", "PUX", "DRZ") ~ "Small demersals",
grouped_taxa %in% c("RAX", "SDX", "CJX", "CLP", "GZP", "FLY", "KYX", "CLP", "MUL", "DSF", "MIL", "THF") ~ "Small pelagics",
TRUE ~ NA_character_
)) %>%
dplyr::select(-grouped_taxa) %>%
dplyr::group_by(fish_group) %>%
dplyr::summarise(dplyr::across(dplyr::where(is.numeric), ~ sum(.x, na.rm = T))) %>%
tidyr::pivot_longer(-c(grouped_taxa, catch), names_to = "nutrient") %>%
dplyr::group_by(nutrient, grouped_taxa) %>%
na.omit() %>%
tidyr::pivot_longer(-c(fish_group, catch), names_to = "nutrient") %>%
dplyr::group_by(nutrient, fish_group) %>%
dplyr::summarise(value = sum(value)) %>%
dplyr::arrange(-value, .by_group = TRUE) %>%
dplyr::slice_head(n = 10) %>%
dplyr::left_join(catch_groups_name) %>%
dplyr::select(-grouped_taxa) %>%
dplyr::select(catch_name, nutrient, value) %>%
dplyr::select(fish_group, nutrient, value) %>%
dplyr::ungroup() %>%
dplyr::mutate(
nutrient = as.factor(nutrient),
catch_name = tidytext::reorder_within(catch_name, value, nutrient)
fish_group = ifelse(fish_group %in% c("Shrimps", "Molluscs", "Cephalopods", "Crustaceans"), "Other groups", fish_group),
fish_group = tidytext::reorder_within(fish_group, value, nutrient)
) %>%
dplyr::filter(!nutrient == "selenium") %>%
dplyr::mutate(
Expand All @@ -129,98 +142,102 @@ timor.nutrients::region_stats %>%
TRUE ~ nutrient
)
) %>%
ggplot(aes(value / 1000, catch_name, fill = nutrient)) +
ggplot(aes(value / 1000, fish_group, fill = nutrient)) +
theme_minimal() +
geom_col(alpha = 0.85) +
facet_wrap(. ~ nutrient, ncol = 2, scales = "free") +
tidytext::scale_y_reordered() +
labs(x = "tons", y = "") +
labs(x = "Tons", y = "") +
theme(legend.position = "") +
scale_fill_manual(values = timor.nutrients::palettes$nutrients_palette)
```

## Nutrional and price values

```{r echo=FALSE, fig.height=3.5, fig.width=6, message=FALSE, warning=FALSE, fig.cap="Comparative analysis of nutritional score versus economic accessibility for key fish groups. This scatter plot displays the relationship between the cumulative nutritional score and the market price for various fish groups within Timor-Leste fishery. The x-axis quantifies the cumulative contribution to the Recommended Nutrient Intake (RNI) for six essential nutrients (zinc, protein, omega-3, calcium, iron, vitamin A) from a 100g portion of each fish group. The y-axis represents the average market price per kilogram for each group. Dot size and the accompanying numerical labels reflect the relative catch percentage of each group, serving as an index of accessibility and availability. "}
revenue_dat <-
timor.nutrients::catch_data %>%
tidyr::unnest(landing_catch) %>%
tidyr::unnest(length_frequency) %>%
tidyr::unnest(landing_catch) %>%
tidyr::unnest(length_frequency) %>%
dplyr::filter(!is.na(.data$weight), !is.na(landing_value)) %>%
dplyr::group_by(landing_id) %>%
dplyr::group_by(landing_id) %>%
dplyr::mutate(n = dplyr::n()) %>%
dplyr::filter(n == 1) %>%
dplyr::select(-n) %>%
dplyr::ungroup() %>%
dplyr::mutate(tot_obs = length(unique(landing_id))) %>%
dplyr::group_by(catch_taxon) %>%
dplyr::mutate(catch_percent = dplyr::n() / tot_obs * 100) %>%
dplyr::filter(catch_taxon %in% c("CLP", "GZP", "TUN", "SDX", "FLY", "CGX")) %>%
dplyr::filter(n == 1) %>%
dplyr::select(-n) %>%
dplyr::ungroup() %>%
dplyr::mutate(tot_obs = length(unique(landing_id))) %>%
dplyr::group_by(catch_taxon) %>%
dplyr::mutate(catch_percent = dplyr::n() / tot_obs * 100) %>%
dplyr::filter(catch_taxon %in% c("CLP", "GZP", "TUN", "SDX", "FLY", "CGX")) %>%
dplyr::group_by(.data$landing_id, .data$catch_taxon) %>%
dplyr::summarise(
landing_value = dplyr::first(landing_value),
catch_percent = dplyr::first(catch_percent),
dplyr::across(
c(.data$weight:.data$Vitamin_A_mu),
~ sum(.x)
))
)
)
models <-
revenue_dat %>%
dplyr::ungroup() %>%
dplyr::select(catch_taxon, landing_value, weight) %>%
split(.$catch_taxon) %>%
purrr::map(~lm(log(landing_value) ~ log(weight), data = .x)) %>%
purrr::map(~predict(.x, data.frame(weight = log(100)))) %>%
dplyr::bind_rows(.id = "catch_taxon") %>%
dplyr::rename(price = `1`) %>%
models <-
revenue_dat %>%
dplyr::ungroup() %>%
dplyr::select(catch_taxon, landing_value, weight) %>%
split(.$catch_taxon) %>%
purrr::map(~ lm(log(landing_value) ~ log(weight), data = .x)) %>%
purrr::map(~ predict(.x, data.frame(weight = log(100)))) %>%
dplyr::bind_rows(.id = "catch_taxon") %>%
dplyr::rename(price = `1`) %>%
dplyr::mutate(price = round(exp(price) * 10, 2))
revenue_dat <-
revenue_dat %>%
rename_nutrients_mu() %>%
tidyr::pivot_longer(-c(landing_id:weight), names_to = "nutrient") %>%
dplyr::filter(!nutrient == "selenium") %>%
dplyr::left_join(RDI_tab) %>%
dplyr::ungroup() %>%
dplyr::mutate(value = value / weight * 100,
inds = value / conv_factor * 100) %>%
dplyr::group_by(landing_id, catch_taxon) %>%
dplyr::mutate(inds_100 = sum(inds)) %>%
dplyr::group_by(catch_taxon) %>%
revenue_dat <-
revenue_dat %>%
rename_nutrients_mu() %>%
tidyr::pivot_longer(-c(landing_id:weight), names_to = "nutrient") %>%
dplyr::filter(!nutrient == "selenium") %>%
dplyr::left_join(RDI_tab) %>%
dplyr::ungroup() %>%
dplyr::mutate(
value = value / weight * 100,
inds = value / conv_factor * 100
) %>%
dplyr::group_by(landing_id, catch_taxon) %>%
dplyr::mutate(inds_100 = sum(inds)) %>%
dplyr::group_by(catch_taxon) %>%
dplyr::summarise(
catch_percent = dplyr::first(catch_percent),
inds = dplyr::first(inds_100)
) %>%
dplyr::left_join(models) %>%
dplyr::rename(interagency_code = catch_taxon) %>%
dplyr::left_join(timor.nutrients::catch_groups, by = "interagency_code") %>%
) %>%
dplyr::left_join(models) %>%
dplyr::rename(interagency_code = catch_taxon) %>%
dplyr::left_join(timor.nutrients::catch_groups, by = "interagency_code") %>%
dplyr::select(catch_name, catch_percent, price, inds)
revenue_dat %>%
ggplot(aes(inds, price, size = catch_percent, color = catch_name)) +
theme_minimal() +
geom_point()+
geom_text(aes(label = round(catch_percent,1)), color = "grey30", size = 3.5, vjust = -1.2)+
scale_size(range = c(2, 8))+
coord_cartesian(xlim = c(75, 130), ylim = c(0, 6))+
scale_x_continuous(labels = scales::label_percent(scale = 1))+
scale_y_continuous(labels = scales::label_dollar())+
scale_color_viridis_d(alpha = 0.85)+
theme(panel.grid.minor = element_blank())+
guides(size = "none")+
labs(x = "Cumulative nutrient score",
y = "Price (USD / kg)",
color = "Fish group")
geom_point() +
geom_text(aes(label = round(catch_percent, 1)), color = "grey30", size = 3.5, vjust = -1.2) +
scale_size(range = c(2, 8)) +
coord_cartesian(xlim = c(75, 130), ylim = c(0, 6)) +
scale_x_continuous(labels = scales::label_percent(scale = 1)) +
scale_y_continuous(labels = scales::label_dollar()) +
scale_color_viridis_d(alpha = 0.85) +
theme(panel.grid.minor = element_blank()) +
guides(size = "none") +
labs(
x = "Cumulative nutrient score",
y = "Price (USD / kg)",
color = "Fish group"
)
```


## Habitat and gear type

```{r echo=FALSE, fig.height=8, fig.width=7, message=FALSE, warning=FALSE, fig.cap="Sankey diagram showing the relative distribution of key nutrients across various marine habitats and the corresponding extraction by different fishing gear types used in Timor-Est small-scale fisheries."}
```{r echo=FALSE, fig.height=7, fig.width=7, message=FALSE, warning=FALSE, fig.cap="Sankey diagram showing the relative distribution of key nutrients across various marine habitats and the corresponding extraction by different fishing gear types used in Timor-Est small-scale fisheries."}
parallel_plot <-
timor.nutrients::kobo_trips %>%
dplyr::select(habitat, gear_type, Selenium_mu:Vitamin_A_mu) %>%
Expand Down Expand Up @@ -301,7 +318,6 @@ parallel_plot %>%
### A focus on habitats nutritional contribution

```{r echo=FALSE, fig.height=6, fig.width=7, message=FALSE, warning=FALSE, fig.cap="The bar chart illustrates the contribution of each habitat to the Recommended Nutrient Intake (RNI) for six fundamental nutrients, based on a 100g portion. Each bar is a color-segmented stacked visual, with distinct hues corresponding to individual nutrients, and white numbers within indicating the specific percentage contribution of each nutrient."}
habitat_nutrients <-
timor.nutrients::kobo_trips %>%
dplyr::select(habitat, weight:Vitamin_A_mu) %>%
Expand All @@ -328,31 +344,30 @@ habitat_nutrients <-
ggplot2::ggplot() +
ggplot2::theme_minimal() +
ggchicklet::geom_chicklet(habitat_nutrients,
mapping = ggplot2::aes(
y = inds_kg,
x = reorder(habitat, inds_kg),
fill = nutrient
),
position = ggplot2::position_stack(reverse = FALSE),
alpha = 0.8,
width = 0.8
mapping = ggplot2::aes(
y = inds_kg,
x = reorder(habitat, inds_kg),
fill = nutrient
),
position = ggplot2::position_stack(reverse = FALSE),
alpha = 0.8,
width = 0.8
) +
ggplot2::geom_text(habitat_nutrients,
mapping = ggplot2::aes(
y = inds_kg,
x = reorder(habitat, inds_kg),
label = round(inds_kg, 1),
group = nutrient
),
position = ggplot2::position_stack(0.5, reverse = FALSE),
color = "white",
size = 3
mapping = ggplot2::aes(
y = inds_kg,
x = reorder(habitat, inds_kg),
label = round(inds_kg, 1),
group = nutrient
),
position = ggplot2::position_stack(0.5, reverse = FALSE),
color = "white",
size = 3
) +
ggplot2::scale_fill_manual(values = timor.nutrients::palettes$nutrients_palette) +
ggplot2::scale_color_manual(values = timor.nutrients::palettes$nutrients_palette) +
ggplot2::scale_y_continuous(labels = scales::label_percent(scale = 1)) +
ggplot2::coord_flip(expand = FALSE) +
ggplot2::theme(legend.position = "bottom") +
ggplot2::labs(x = "", fill = "", y = "Matched RNI from 100g portion")
```
Loading

0 comments on commit 7530c92

Please sign in to comment.