This file contains one student’s fledgling attempt to wrangle data and create interesting and useful graphics to illustrate my comprehension in R.

library(tidyverse)
library(readr)
library(dplyr)
library(RColorBrewer)
library(rcartocolor)
library(kableExtra)
library(patchwork)
library(ggplot2)
library(dplyr)

The Data

The Food and Agriculture Organization of the United Nations (FAO) supports governments and other organizations to design policies and programs to end hunger, promote food security, and enhance sustainable agriculture around the world. They collect data about food and agriculture for over 245 countries and territories.

I pulled data from their Suite of Food Insecurity Indicators. This set can be filtered by country and specific indicators related to food access, food supply stability and utilization, and overall prevalence of food insecurity malnutrition, etc.

I initially wanted to look at a handful of Middle Eastern countries, but found that many of these countries are missing key data points. This was an issue that continually thwarted data wrangling progess. It makes sense that these data are most often missing from the poorest countries - basic needs resources are already lacking or extremely fragile, making data collection less of a priority for governments.

Moderate and Severe Food Insecurity around the World

Some helpful definitions to orient us to this data:

The FAO definition of food insecurity is: “A situation that exists when people lack secure access to sufficient amounts of safe and nutritious food for normal growth and development and an active and healthy life.”

The FAO uses a multidemential index to “score” food insecurity levels. “Moderate” food insecurity may invovle reduced foo intake and the experience of hunger due to self-rationing. “Severe” food insecurity describes more acute physical sensations of hunger and potentially evidence of malnutrition as a resuld of muched reduced food intake. For the most, these visualizations look at combined prevalence of moderate and severe food insecurity, though sometimes explore severe food insecurity specifically.

Consider how rates of food insecurity vary around the world:

world <- read_csv("FAOSTAT_data_en_10-3-2022.csv") 

world2 <- world %>% 
  select(isocode = `Area Code (M49)`,  Region = Area,
         itemcode = `Item Code`, year = `Year Code`,
         yearlabel = Year, value = Value) %>% 
  pivot_wider(names_from = itemcode, values_from = value) %>% 
  rename(severe_percent = `210400`, moderate_percent = `210090`)
  
world2 %>% 
  select(Region, moderate_percent) %>% 
  kbl(align = "c") %>% 
  kable_styling(bootstrap_options = c("striped", "hover")) %>% 
  scroll_box(height = "300px")
Region moderate_percent
World 29.3
Africa 57.9
Northern America and Europe 8.0
Latin America and the Caribbean 40.6
Asia 24.6
Oceania 13.0
world2 %>% 
ggplot(aes(x=Region, y=moderate_percent, size = severe_percent, fill = Region)) +
    geom_point(alpha=0.7, shape=21) +
    theme(legend.position = "none")+
    ylab("Moderate + Severe Food Insecurity") +
    xlab("Region")

Into Africa

In Africa, there are 278 million people facing hunger. 23% of the contininent is severely food insecure.

Countries in the Middle East and North Africa are among the most at risk of famine on the planet. Already a hotspot of conflict, humanitarian crises, and socio-economic instability, with dangerously increasing temperatures, this region also suffers from food and water shortages, and livability of the area.

This bar graph illustrates GDP for countries in the Middle East. We can see that Isreal and Saudi Arabia have the highest GDP per capita,while Ethiopia and Somalia have the lowest. This consistent with UN reports that Somalia is the second poorest country in the world - current rates of famine have especially worsened from supply disruptions resulting from Russia’s invasion of Ukraine.

UN <- read_csv("FAOSTAT_data_en_9-20-2022.csv") %>% 
  filter(Item == "Gross domestic product per capita, PPP, (constant 2017 international $)") %>% 
  mutate (pop="Total",
          `Item Code` = as.character(`Item Code`)) 

UN_wider <- UN%>% 
  pivot_wider(names_from = Item, values_from = Value) %>% 
  rename(GDP = `Gross domestic product per capita, PPP, (constant 2017 international $)`,
         country = Area) 

UN_wider %>% 
  ggplot(aes(x = country, y = GDP)) +
  geom_col(position = "dodge", fill = "light green") +
  theme_minimal () +
  labs(x = "Country", y = "GDP Per Capita",
       title = "GDP by Country") 

More Datasets!Gender and Food Insecurity

Because there was so much missing data, I tried to look at data points that were available for the most countries. After some cleaning, here are the data I use to explore gender and food insecurity in African countries:

fao <- read_csv("FAOSTAT_data_en_9-23-2022.csv")

# reshape
fao2 <- fao %>% 
  # rename some vars for easier use
  select(isocode = `Area Code (M49)`,  country = Area,
         itemcode = `Item Code`, year = `Year Code`,
         yearlabel = Year, value = Value) %>% 
  # I need a variable that distinguishes which group the value is for
  mutate(group = case_when(
    str_detect(itemcode, "M") ~ "Male",
    str_detect(itemcode, "F") ~ "Female",
    TRUE ~ "All"),
    itemcode = str_remove(itemcode, "[A-Z]")) %>% 
  # and then removed the string from item code so the same type of 
  # value (percent severe food insecurity) is understood as the same
  # then made it wide
  pivot_wider(names_from = itemcode, values_from = value) %>% 
  # and renamed the item codes for easier understanding
  rename(severe_percent = `210401`, moderate_percent = `210091`,
         severe_number = `210071`, moderate_number = `210081`)

fao2 %>% 
  kbl(align = "c") %>% 
  kable_styling(bootstrap_options = c("striped", "hover")) %>% 
  scroll_box(height = "300px")
isocode country year yearlabel group severe_percent moderate_percent severe_number moderate_number
12 Algeria 20162018 2016-2018 All 11.4 19.7 4.7 8.2
12 Algeria 20172019 2017-2019 All 9.3 17.6 3.9 7.4
12 Algeria 20182020 2018-2020 All 6.9 17.6 3.0 7.6
12 Algeria 20192021 2019-2021 All 6.2 19.0 2.7 8.3
12 Algeria 20162018 2016-2018 Male 9.8 17.3 1.4 2.5
12 Algeria 20172019 2017-2019 Male 8.0 15.0 1.2 2.2
12 Algeria 20182020 2018-2020 Male 6.1 16.0 0.9 2.4
12 Algeria 20192021 2019-2021 Male 6.4 18.7 1.0 2.9
12 Algeria 20162018 2016-2018 Female 12.0 20.3 1.7 2.9
12 Algeria 20172019 2017-2019 Female 9.6 17.7 1.4 2.6
12 Algeria 20182020 2018-2020 Female 6.5 16.3 1.0 2.4
12 Algeria 20192021 2019-2021 Female 4.7 15.6 0.7 2.4
818 Egypt 20162018 2016-2018 All 8.6 33.1 8.3 31.9
818 Egypt 20172019 2017-2019 All 7.4 31.2 7.3 30.7
818 Egypt 20182020 2018-2020 All 6.7 27.8 6.8 27.9
818 Egypt 20192021 2019-2021 All 7.1 27.3 7.3 27.9
818 Egypt 20162018 2016-2018 Male 6.8 27.6 2.2 8.8
818 Egypt 20172019 2017-2019 Male 6.4 26.6 2.1 8.7
818 Egypt 20182020 2018-2020 Male 5.8 24.5 1.9 8.1
818 Egypt 20192021 2019-2021 Male 5.8 23.7 1.9 8.0
818 Egypt 20162018 2016-2018 Female 9.1 35.5 2.9 11.3
818 Egypt 20172019 2017-2019 Female 7.2 32.5 2.4 10.6
818 Egypt 20182020 2018-2020 Female 6.3 27.7 2.1 9.2
818 Egypt 20192021 2019-2021 Female 6.8 26.8 2.3 9.1
434 Libya 20162018 2016-2018 All 14.3 33.2 0.9 2.2
434 Libya 20172019 2017-2019 All 16.7 35.7 1.1 2.4
434 Libya 20182020 2018-2020 All 18.6 37.4 1.3 2.5
434 Libya 20192021 2019-2021 All 20.7 39.4 1.4 2.7
434 Libya 20162018 2016-2018 Male 10.6 27.8 0.3 0.7
434 Libya 20172019 2017-2019 Male 12.5 30.1 0.3 0.7
434 Libya 20182020 2018-2020 Male 13.5 30.6 0.3 0.7
434 Libya 20192021 2019-2021 Male 15.0 32.2 0.4 0.8
434 Libya 20162018 2016-2018 Female 18.3 38.6 0.4 0.9
434 Libya 20172019 2017-2019 Female 21.1 41.4 0.5 1.0
434 Libya 20182020 2018-2020 Female 23.6 43.6 0.6 1.1
434 Libya 20192021 2019-2021 Female 26.2 45.9 0.6 1.1
504 Morocco 20162018 2016-2018 All 5.7 26.1 2.0 9.3
504 Morocco 20172019 2017-2019 All 6.0 26.7 2.2 9.6
504 Morocco 20182020 2018-2020 All 7.1 28.0 2.6 10.2
504 Morocco 20192021 2019-2021 All 9.7 31.6 3.6 11.7
504 Morocco 20162018 2016-2018 Male 4.9 23.1 0.6 2.9
504 Morocco 20172019 2017-2019 Male 5.3 24.6 0.7 3.2
504 Morocco 20182020 2018-2020 Male 6.5 26.1 0.9 3.4
504 Morocco 20192021 2019-2021 Male 9.2 30.1 1.2 4.0
504 Morocco 20162018 2016-2018 Female 6.1 27.2 0.8 3.6
504 Morocco 20172019 2017-2019 Female 6.2 27.2 0.8 3.6
504 Morocco 20182020 2018-2020 Female 7.5 28.9 1.0 3.9
504 Morocco 20192021 2019-2021 Female 9.8 32.3 1.4 4.4
729 Sudan 20162018 2016-2018 All 15.4 46.4 6.3 19.0
729 Sudan 20172019 2017-2019 All 16.4 48.9 6.8 20.4
729 Sudan 20182020 2018-2020 All 16.8 49.4 7.2 21.2
729 Sudan 20192021 2019-2021 All 17.4 50.7 7.6 22.2
729 Sudan 20162018 2016-2018 Male NA NA NA NA
729 Sudan 20172019 2017-2019 Male NA NA NA NA
729 Sudan 20182020 2018-2020 Male NA NA NA NA
729 Sudan 20192021 2019-2021 Male NA NA NA NA
729 Sudan 20162018 2016-2018 Female NA NA NA NA
729 Sudan 20172019 2017-2019 Female NA NA NA NA
729 Sudan 20182020 2018-2020 Female NA NA NA NA
729 Sudan 20192021 2019-2021 Female NA NA NA NA
788 Tunisia 20162018 2016-2018 All 9.1 20.0 1.0 2.3
788 Tunisia 20172019 2017-2019 All 9.7 22.1 1.1 2.6
788 Tunisia 20182020 2018-2020 All 10.7 25.1 1.2 2.9
788 Tunisia 20192021 2019-2021 All 12.6 28.0 1.5 3.3
788 Tunisia 20162018 2016-2018 Male 8.5 18.7 0.4 0.8
788 Tunisia 20172019 2017-2019 Male 9.0 20.6 0.4 0.9
788 Tunisia 20182020 2018-2020 Male 9.7 23.8 0.4 1.0
788 Tunisia 20192021 2019-2021 Male 12.3 27.2 0.5 1.2
788 Tunisia 20162018 2016-2018 Female 9.1 19.9 0.4 0.9
788 Tunisia 20172019 2017-2019 Female 9.8 22.5 0.4 1.0
788 Tunisia 20182020 2018-2020 Female 11.1 25.7 0.5 1.2
788 Tunisia 20192021 2019-2021 Female 12.1 28.0 0.6 1.3

Out of the six African countries from this data set, Libya and Sudan have the highest rates of severe food insecurity. Notably, in all countries reported food insecurity by sex, women consistently experience higher rates of food insecurity than men.

fao2 %>% 
  filter(year == 20182020, group == 'All') %>% 
  ggplot(aes(y = country, x = severe_percent)) +
  geom_point(size = 6, color = "#0072B2")+
  geom_segment(aes(x = 0, xend = severe_percent, y = country, yend = country))+
  labs(y = "Country", x = "Prevalence of Severe Food Insecurity (%)",
     title = "Severe Food Insecurity by Country and Gender") 

..and another way to look at our data:

fao2 %>% 
  filter(year == 20182020) %>% 
  ggplot(aes(x = country, y = severe_percent, fill = group)) +
  geom_col(position = "dodge")+
  scale_fill_manual(values = c("#009bda", "#969696", "#97b5cf")) +
  labs(x = "Country", y = "Prevalence of Severe Food Insecurity (%)",
     title = "Severe Food Insecurity by Country and Gender") +
  
  scale_fill_manual(values = c("#969696", "#009bda", "#97b5cf"),
                    name = "")

We can see the gap between male and female food insecurity rates more prominently with this scatter plot:

fao2 %>% 
  filter(year == 20182020,
         group %in% c("Male", "Female")) %>% 
  ggplot(aes(y = country, x = severe_percent, color = group)) +
  geom_point(size = 2) +
  labs(x = "Country", y = "Prevalence of Severe Food Insecurity (%)",
       title = "Food Insecurity Gap by Gender") +
  theme_minimal()