The United Nations Food and Agriculture Organization publication, The State of Food Security and Nutrition in the World 2022 (https://www.fao.org/documents/card/en/c/cc0639en) might lead one to the conclusion that it’s an elsewhere problem. That the people who are suffering malnutrition and starvation are “elsewhere”, not in our backyard. For this assignment you will need to take a closer look here at home (the US).
library(tidyverse)
library(httr)
library(jsonlite)
library(dplyr)
library(ggplot2)
library(reshape2)
library(usmap)
library(tinytex)
library(paletteer)
url <- "https://raw.githubusercontent.com/Stevee-G/Data608/refs/heads/main/Assignment6/foodsecurity_csv_datafiles/foodsecurity-all-households-2024.csv"
url1 <- "https://raw.githubusercontent.com/Stevee-G/Data608/refs/heads/main/Assignment6/foodsecurity_csv_datafiles/foodsecurity-child-trends-2024.csv"
url2 <- "https://raw.githubusercontent.com/Stevee-G/Data608/refs/heads/main/Assignment6/foodsecurity_csv_datafiles/foodsecurity-educ-emp-dis-2024.csv"
url3 <- "https://raw.githubusercontent.com/Stevee-G/Data608/refs/heads/main/Assignment6/foodsecurity_csv_datafiles/foodsecurity-state-2024.csv"
url4 <- "https://raw.githubusercontent.com/aruljohn/us-states/refs/heads/master/states.csv"
all_hh <- read_csv(url)
ct <- read_csv(url1)
eed <- read_csv(url2)
state <- read_csv(url3)
state_abbr <- read_csv(url4)
glimpse(all_hh)
## Rows: 30
## Columns: 13
## $ Year <dbl> 2024, 2024, 2024, 2024, 2024, 2024, 2…
## $ Category <chr> "All households", "Household composit…
## $ Subcategory <chr> NA, "With children < 18 years", "With…
## $ `Sub-subcategory` <chr> NA, NA, "With children < 6 years", "M…
## $ Total <dbl> 134062, 36599, 14767, 24051, 8696, 33…
## $ `Food secure-1,000` <dbl> 115722, 29860, 12133, 21429, 5497, 25…
## $ `Food secure-percent` <dbl> 86.3, 81.6, 82.2, 89.1, 63.2, 76.2, 7…
## $ `Food insecure-1,000` <dbl> 18340, 6739, 2634, 2622, 3199, 808, 1…
## $ `Food insecure-percent` <dbl> 13.7, 18.4, 17.8, 10.9, 36.8, 23.8, 2…
## $ `Low food security-1,000` <dbl> 11138, 4738, 1947, 1974, 2081, 610, 7…
## $ `Low food security-percent` <dbl> 8.3, 12.9, 13.2, 8.2, 23.9, 18.0, 15.…
## $ `Very low food security-1,000` <dbl> 7202, 2001, 687, 648, 1118, 198, 38, …
## $ `Very low food security-percent` <dbl> 5.4, 5.5, 4.7, 2.7, 12.9, 5.8, 8.2, 5…
glimpse(ct)
## Rows: 2
## Columns: 11
## $ Year <dbl> 2024, …
## $ Category <chr> "Child…
## $ Total <dbl> 72179,…
## $ `Food-secure households-1,000` <dbl> 58088,…
## $ `Food-secure households-percent` <dbl> 80.5, …
## $ `Food-insecure households-1,000` <dbl> 14091,…
## $ `Food-insecure households-percent` <dbl> 19.5, …
## $ `Households with food-insecure children-1,000` <dbl> 7306, …
## $ `Households with food-insecure children-percent` <dbl> 10.1, …
## $ `Households with very low food security among children-1,000` <dbl> 751, 3…
## $ `Households with very low food security among children-percent` <dbl> 1.0, 0…
glimpse(eed)
## Rows: 16
## Columns: 11
## $ Year <dbl> 2024, 2024, 2024, 2024, 2024, 2024, 2…
## $ Category <chr> "All households", "All households", "…
## $ Subcategory <chr> NA, "Employment", "Employment", "Empl…
## $ `Sub-subcategory` <chr> NA, "Full-time", "Retired", "Part-tim…
## $ Total <dbl> 134062, 86983, 31097, 6024, 971, 1789…
## $ `Food insecure-1,000` <dbl> 18341, 10406, 2767, 1208, 404, 809, 1…
## $ `Food insecure-percent` <dbl> 13.7, 12.0, 8.9, 20.1, 41.6, 45.2, 44…
## $ `Food insecure-share` <dbl> 100.0, 56.7, 15.1, 6.6, 2.2, 4.4, 10.…
## $ `Very low food security-1,000` <dbl> 7202, 3777, 956, 487, 214, 327, 1072,…
## $ `Very low food security-percent` <dbl> 5.4, 4.3, 3.1, 8.1, 22.0, 18.3, 24.4,…
## $ `Very low food security-share` <dbl> 100.0, 52.4, 13.3, 6.8, 3.0, 4.5, 14.…
glimpse(state)
## Rows: 52
## Columns: 6
## $ Year <dbl> 2024, 2024, 2024, 2024, 2024,…
## $ State <chr> "U.S.", "AK", "AL", "AR", "AZ…
## $ `Food insecurity prevalence` <dbl> 13.3, 13.0, 12.1, 19.4, 13.1,…
## $ `Food insecurity margin of error` <dbl> 0.40, 2.53, 2.23, 1.67, 1.68,…
## $ `Very low food security prevalence` <dbl> 5.2, 6.5, 4.6, 7.6, 5.6, 4.4,…
## $ `Very low food security margin of error` <dbl> 0.21, 2.10, 1.31, 1.52, 1.03,…
glimpse(state_abbr)
## Rows: 65
## Columns: 3
## $ ABBREVIATION <chr> "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA…
## $ NAME <chr> "Alabama", "Alaska", "Arizona", "Arkansas", "California",…
## $ TYPE <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
hh_comp <- all_hh %>%
filter(Category == "Household composition") %>%
group_by(Subcategory) %>%
summarize(
`Food secure-percent` = round(mean(`Food secure-percent`),2),
`Food insecure-percent` = round(mean(`Food insecure-percent`),2),
`Low food security-percent` = round(mean(`Low food security-percent`),2),
`Very low food security-percent` = round(mean(`Very low food security-percent`),2)
) %>%
pivot_longer(
cols = c(`Food secure-percent`, `Food insecure-percent`,
`Low food security-percent`, `Very low food security-percent`),
names_to = "Food Security Type",
values_to = "Percent"
)
glimpse(hh_comp)
## Rows: 12
## Columns: 3
## $ Subcategory <chr> "With children < 18 years", "With children < 18 y…
## $ `Food Security Type` <chr> "Food secure-percent", "Food insecure-percent", "…
## $ Percent <dbl> 78.08, 21.92, 15.30, 6.63, 89.40, 10.60, 6.50, 4.…
re_hh <- all_hh %>%
filter(Category == "Race/ethnicity of households") %>%
group_by(Subcategory) %>%
summarize(
`Food secure-percent` = round(mean(`Food secure-percent`),2),
`Food insecure-percent` = round(mean(`Food insecure-percent`),2),
`Low food security-percent` = round(mean(`Low food security-percent`),2),
`Very low food security-percent` = round(mean(`Very low food security-percent`),2)
) %>%
pivot_longer(
cols = c(`Food secure-percent`, `Food insecure-percent`,
`Low food security-percent`, `Very low food security-percent`),
names_to = "Food Security Type",
values_to = "Percent"
)
glimpse(re_hh)
## Rows: 16
## Columns: 3
## $ Subcategory <chr> "Black non-Hispanic", "Black non-Hispanic", "Blac…
## $ `Food Security Type` <chr> "Food secure-percent", "Food insecure-percent", "…
## $ Percent <dbl> 75.6, 24.4, 13.8, 10.5, 79.8, 20.2, 13.8, 6.4, 88…
ipr <- all_hh %>%
filter(Category == "Household income-to-poverty ratio") %>%
group_by(Subcategory) %>%
summarize(
`Food secure-percent` = round(mean(`Food secure-percent`),2),
`Food insecure-percent` = round(mean(`Food insecure-percent`),2),
`Low food security-percent` = round(mean(`Low food security-percent`),2),
`Very low food security-percent` = round(mean(`Very low food security-percent`),2)
) %>%
pivot_longer(
cols = c(`Food secure-percent`, `Food insecure-percent`,
`Low food security-percent`, `Very low food security-percent`),
names_to = "Food Security Type",
values_to = "Percent"
)
glimpse(ipr)
## Rows: 20
## Columns: 3
## $ Subcategory <chr> "1.85 and over", "1.85 and over", "1.85 and over"…
## $ `Food Security Type` <chr> "Food secure-percent", "Food insecure-percent", "…
## $ Percent <dbl> 92.1, 7.9, 5.0, 3.0, 89.5, 10.5, 6.5, 4.0, 60.6, …
ar <- all_hh %>%
filter(Category == "Area of residence") %>%
group_by(Subcategory) %>%
summarize(
`Food secure-percent` = round(mean(`Food secure-percent`),2),
`Food insecure-percent` = round(mean(`Food insecure-percent`),2),
`Low food security-percent` = round(mean(`Low food security-percent`),2),
`Very low food security-percent` = round(mean(`Very low food security-percent`),2)
) %>%
pivot_longer(
cols = c(`Food secure-percent`, `Food insecure-percent`,
`Low food security-percent`, `Very low food security-percent`),
names_to = "Food Security Type",
values_to = "Percent"
)
glimpse(ar)
## Rows: 8
## Columns: 3
## $ Subcategory <chr> "Inside metropolitan area", "Inside metropolitan …
## $ `Food Security Type` <chr> "Food secure-percent", "Food insecure-percent", "…
## $ Percent <dbl> 86.27, 13.73, 8.23, 5.47, 84.10, 15.90, 9.70, 6.20
cgr <- all_hh %>%
filter(Category == "Census geographic region") %>%
group_by(Subcategory) %>%
summarize(
`Food secure-percent` = round(mean(`Food secure-percent`),2),
`Food insecure-percent` = round(mean(`Food insecure-percent`),2),
`Low food security-percent` = round(mean(`Low food security-percent`),2),
`Very low food security-percent` = round(mean(`Very low food security-percent`),2)
) %>%
pivot_longer(
cols = c(`Food secure-percent`, `Food insecure-percent`,
`Low food security-percent`, `Very low food security-percent`),
names_to = "Food Security Type",
values_to = "Percent"
)
glimpse(cgr)
## Rows: 16
## Columns: 3
## $ Subcategory <chr> "Midwest", "Midwest", "Midwest", "Midwest", "Nort…
## $ `Food Security Type` <chr> "Food secure-percent", "Food insecure-percent", "…
## $ Percent <dbl> 86.7, 13.3, 8.0, 5.3, 87.8, 12.2, 7.4, 4.8, 85.0,…
ct_trim <- ct %>%
select(Category, `Food-secure households-percent`,
`Food-insecure households-percent`,
`Households with food-insecure children-percent`,
`Households with very low food security among children-percent`) %>%
pivot_longer(
cols = c(`Food-secure households-percent`, `Food-insecure households-percent`,
`Households with food-insecure children-percent`,
`Households with very low food security among children-percent`),
names_to = "Food Security Type",
values_to = "Percent"
)
glimpse(ct_trim)
## Rows: 8
## Columns: 3
## $ Category <chr> "Children - by food security status of household"…
## $ `Food Security Type` <chr> "Food-secure households-percent", "Food-insecure …
## $ Percent <dbl> 80.5, 19.5, 10.1, 1.0, 81.6, 18.4, 9.1, 0.9
emp <- eed %>%
filter(Subcategory == 'Employment') %>%
select(`Sub-subcategory`, `Food insecure-percent`,
`Very low food security-percent`) %>%
pivot_longer(
cols = c(`Food insecure-percent`,`Very low food security-percent`),
names_to = "Food Security Type",
values_to = "Percent"
)
glimpse(emp)
## Rows: 14
## Columns: 3
## $ `Sub-subcategory` <chr> "Full-time", "Full-time", "Retired", "Retired", "…
## $ `Food Security Type` <chr> "Food insecure-percent", "Very low food security-…
## $ Percent <dbl> 12.0, 4.3, 8.9, 3.1, 20.1, 8.1, 41.6, 22.0, 45.2,…
edu <- eed %>%
filter(Subcategory == 'Education') %>%
select(`Sub-subcategory`, `Food insecure-percent`,
`Very low food security-percent`) %>%
pivot_longer(
cols = c(`Food insecure-percent`,`Very low food security-percent`),
names_to = "Food Security Type",
values_to = "Percent"
)
glimpse(edu)
## Rows: 8
## Columns: 3
## $ `Sub-subcategory` <chr> "Less than high school", "Less than high school",…
## $ `Food Security Type` <chr> "Food insecure-percent", "Very low food security-…
## $ Percent <dbl> 30.4, 13.2, 21.7, 7.8, 18.3, 7.6, 6.1, 2.4
dis <- eed %>%
filter(Subcategory == 'Disability status') %>%
select(`Sub-subcategory`, `Food insecure-percent`,
`Very low food security-percent`) %>%
pivot_longer(
cols = c(`Food insecure-percent`,`Very low food security-percent`),
names_to = "Food Security Type",
values_to = "Percent"
)
glimpse(dis)
## Rows: 8
## Columns: 3
## $ `Sub-subcategory` <chr> "Not in labor force due to disability", "Not in l…
## $ `Food Security Type` <chr> "Food insecure-percent", "Very low food security-…
## $ Percent <dbl> 34.9, 16.4, 27.3, 13.6, 11.7, 4.5, 10.5, 3.6
state_trim <- inner_join(state, state_abbr,
join_by(State == ABBREVIATION),
relationship = "one-to-one") %>%
select(NAME, `Food insecurity prevalence`,
`Very low food security prevalence`) %>%
mutate(state = NAME)
glimpse(state_trim)
## Rows: 51
## Columns: 4
## $ NAME <chr> "Alaska", "Alabama", "Arkansas", "…
## $ `Food insecurity prevalence` <dbl> 13.0, 12.1, 19.4, 13.1, 12.5, 10.5…
## $ `Very low food security prevalence` <dbl> 6.5, 4.6, 7.6, 5.6, 4.4, 4.3, 5.7,…
## $ state <chr> "Alaska", "Alabama", "Arkansas", "…
plot_usmap(data = state_trim, values = "Food insecurity prevalence", color = "black") +
scale_fill_continuous(low = "whitesmoke",
high = "darkorange",
name = "Level of Prevalence",
label = scales::comma) +
labs(title = "Heatmap: Food Insecurity Prevalence Across the States") +
theme(legend.position = "right") +
theme(plot.title = element_text(hjust = 0.5))
plot_usmap(data = state_trim, values = "Very low food security prevalence", color = "black") +
scale_fill_continuous(low = "whitesmoke",
high = "darkred",
name = "Level of Prevalence",
label = scales::comma) +
labs(title = "Heatmap: Very Low Food Security Prevalence Across the States") +
theme(legend.position = "right") +
theme(plot.title = element_text(hjust = 0.5))
ggplot(hh_comp, aes(x = Subcategory, y = Percent, fill = `Food Security Type`)) +
geom_bar(stat = "identity") +
scale_fill_paletteer_d('ggsci::orange_material') +
labs(title = "Barplot: Food Security by Household Composition") +
theme_minimal() +
theme(legend.position = "right") +
theme(plot.title = element_text(hjust = 0.5))
ggplot(re_hh, aes(x = Subcategory, y = Percent, fill = `Food Security Type`)) +
geom_bar(stat = "identity") +
scale_fill_paletteer_d('ggsci::orange_material') +
labs(title = "Barplot: Food Security by Race/Ethnicity") +
theme_minimal() +
theme(legend.position = "right") +
theme(plot.title = element_text(hjust = 0.5))
ggplot(ipr, aes(x = Subcategory, y = Percent, fill = `Food Security Type`)) +
geom_bar(stat = "identity") +
scale_fill_paletteer_d('ggsci::orange_material') +
labs(title = "Barplot: Food Security by Income to Poverty Ratio") +
theme_minimal() +
theme(legend.position = "right") +
theme(plot.title = element_text(hjust = 0.5))
ggplot(ar, aes(x = Subcategory, y = Percent, fill = `Food Security Type`)) +
geom_bar(stat = "identity") +
scale_fill_paletteer_d('ggsci::orange_material') +
labs(title = "Barplot: Food Security by Area of Residence") +
theme_minimal() +
theme(legend.position = "right") +
theme(plot.title = element_text(hjust = 0.5))
ggplot(cgr, aes(x = Subcategory, y = Percent, fill = `Food Security Type`)) +
geom_bar(stat = "identity") +
scale_fill_paletteer_d('ggsci::orange_material') +
labs(title = "Barplot: Food Security by Census Geographic Region") +
theme_minimal() +
theme(legend.position = "right") +
theme(plot.title = element_text(hjust = 0.5))
ggplot(ct_trim, aes(x = Category, y = Percent, fill = `Food Security Type`)) +
geom_bar(stat = "identity") +
scale_fill_paletteer_d('ggsci::orange_material') +
labs(title = "Barplot: Food Security by Child Household") +
theme_minimal() +
theme(legend.position = "right") +
theme(plot.title = element_text(hjust = 0.5)) +
coord_flip()
ggplot(emp, aes(x = `Sub-subcategory`, y = Percent, fill = `Food Security Type`)) +
geom_bar(stat = "identity") +
scale_fill_paletteer_d('ggsci::orange_material') +
labs(title = "Barplot: Food Security by Employment") +
theme_minimal() +
theme(legend.position = "bottom") +
theme(plot.title = element_text(hjust = 0.5)) +
coord_flip()
ggplot(edu, aes(x = `Sub-subcategory`, y = Percent, fill = `Food Security Type`)) +
geom_bar(stat = "identity") +
scale_fill_paletteer_d('ggsci::orange_material') +
labs(title = "Barplot: Food Security by Education") +
theme_minimal() +
theme(legend.position = "bottom") +
theme(plot.title = element_text(hjust = 0.5)) +
coord_flip()
ggplot(dis, aes(x = `Sub-subcategory`, y = Percent, fill = `Food Security Type`)) +
geom_bar(stat = "identity") +
scale_fill_paletteer_d('ggsci::orange_material') +
labs(title = "Barplot: Food Security by Disability Status") +
theme_minimal() +
theme(legend.position = "bottom") +
theme(plot.title = element_text(hjust = 0.5)) +
coord_flip()