hh_fs <- read.csv("https://raw.githubusercontent.com/jamilton08/FoodSecurity/main/household_fs.csv") |> rename(cat = Sub.subcategory) |>
  mutate(cat = case_when(cat == "Male head, no spouse" ~ "MH", 
                         cat == "Female head, no spouse" ~ "FH",
                         cat == "Women living alone" ~ "WA", 
                         cat == "Men living alone" ~ "MA", 
                         cat == "Other household with child" ~ "OHC", 
                         cat == "With children < 6 years" ~ "WC", 
                         cat == "Married-couple families" ~ "MC", 
                         cat == "Elderly living alone" ~ "E",
                         cat == "More than one adult" ~ "MTA",   
                         TRUE ~ cat)
         ) |>
  filter(cat %in% c("MH" , "FH" , "WA" , "MA" , "OHC" , "WC", "MC", "E", "MTA")) |>
  rename(sc = Subcategory) |>
  mutate(children = ifelse(sc == "With children < 18 years", "y", "n")) |>
  mutate(sex = case_when(cat == "MH" ~ "m",
                         cat == "MA" ~ "m",
                         cat == "FH" ~ "f",
                         cat == "WA" ~ "f")
  ) |>
  mutate(relationship = case_when(cat == "MH" ~ "s",
                                  cat == "FH" ~ "s",
                                  cat == "WA" ~ "s",
                                  cat == "MA" ~ "s",
                                  cat == "MC" ~ "t",
                                  cat == "MTA" ~ "t")
         )|>
  mutate(age_group = case_when(cat == "MH" ~ "Child",
                                  cat == "FH" ~ "Child",
                                  cat == "WA" ~ "Adult",
                                  cat == "MA" ~ "Adult",
                                  cat == "MTA" ~ "Adult",
                                  cat == "OHC" ~ "Child",
                                  cat == "WC" ~ "Child",
                                  cat == "MC" ~ "Child",
                                  cat == "E" ~ "Elderly")
         )

Generate Data For Gender and Child Analysis

t <- hh_fs |>
     group_by(Year, sex, children) |>
     summarise(food_security = mean(Food.secure.percent) / 100) |>
     na.omit() |>
     mutate(id = str_c(sex, children)) |>
     mutate(groups = case_when(id == "fn" ~ "Female, no Children",
                               id == "fy" ~ "Female, with Children",
                               id == "mn" ~ "Male, no Children",
                               id == "my" ~ "Male, with Children")
            )
## `summarise()` has grouped output by 'Year', 'sex'. You can override using the
## `.groups` argument.

Gender and Guardian Analysis

ggplot(shape=t$groups) + 
geom_line(data=t,aes(x=Year,y= food_security,color=groups),size=1)+
geom_point(data=t,aes(x=Year,y=food_security,color=groups,shape = groups),size=3) + 
theme_bw() + 
  labs(
    title = "Food security status of single individuals",
    subtitle = "The average food security of singles over 22 years, categorized by gender and guardianship status."
  ) + 
  theme(
    plot.title = element_text(color = "#0099f9", size = 20, face = "bold", hjust = 0.5),
    plot.subtitle = element_text(size = 8, face = "bold", hjust = 0.5),
    plot.caption = element_text(face = "italic", hjust = 0),
    panel.border = element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank()
  ) + 
  scale_y_continuous(labels = scales::percent) + 
  ylab("Food Security Percent")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Generate Data For Child Analysis

child_a <- hh_fs |>
     group_by(Year, children) |>
     summarise(food_security = mean(Food.secure.percent) / 100) |>
     na.omit() 
## `summarise()` has grouped output by 'Year'. You can override using the
## `.groups` argument.

Child Food Security Analysis

Singles with kids have less food security then singles without kids.

ggplot(shape=child_a$children) + 
geom_line(data=child_a,aes(x=Year,y= food_security,color=children),size=1)+
geom_point(data=child_a,aes(x=Year,y=food_security,color=children,shape = children),size=3) + 
theme_bw() + 
  labs(
    title = "Average Food Security Status  For Children",
    subtitle = "The average food security of adults with no children vs adults with children over 22 years"
  ) + 
  theme(
    plot.title = element_text(color = "#0099f9", size = 20, face = "bold", hjust = 0.5),
    plot.subtitle = element_text(size = 8, face = "bold", hjust = 0.5),
    plot.caption = element_text(face = "italic", hjust = 0),
    panel.border = element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank()
  ) + 
  scale_y_continuous(labels = scales::percent) + 
  ylab("Food Security Percent") + 
  guides(color = guide_legend(title = "Has Children"), shape = guide_legend(title = "Has Children") ) 

## Generate Data For Age Group Analysis

age_group <- hh_fs |>
     group_by(Year, age_group) |>
     summarise(food_security = mean(Food.secure.percent) / 100) 
## `summarise()` has grouped output by 'Year'. You can override using the
## `.groups` argument.

Age Group Analysis

As you get older you see that the drop off in food security, hence the drop in support makes a difference. This also contradicts the idea that kids have less food security however I believe that families being included gives it a diffirent perspective.

ggplot(shape=age_group$age_group) + 
geom_line(data=age_group,aes(x=Year,y= food_security,color=age_group),size=1)+
geom_point(data=age_group,aes(x=Year,y=food_security,color=age_group,shape = age_group),size=3) + 
theme_bw() + 
  labs(
    title = "Average Food Security Status Categorized By Age Group",
    subtitle = "Food Security Status for Adults, Children and Elders"
  ) + 
  theme(
    plot.title = element_text(color = "#0099f9", size = 15, face = "bold", hjust = 0.5),
    plot.subtitle = element_text(size = 8, face = "bold", hjust = 0.5),
    plot.caption = element_text(face = "italic", hjust = 0),
    panel.border = element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank()
  ) + 
  scale_y_continuous(labels = scales::percent) + 
  ylab("Food Security Percent") + 
  guides(color = guide_legend(title = "Has Children"), shape = guide_legend(title = "Has Children") )

Generate Data For State Food Security Analysis

states_fs <- read.csv("https://raw.githubusercontent.com/jamilton08/FoodSecurity/main/state_fs.csv") |>
filter(Year == "2020–2022")

states_fs <- states_fs[2:nrow(states_fs),]

Food Security By State Analysis

ggplot(states_fs, 
       aes(x=reorder(State, Food.insecurity.prevalence),
           y = Food.insecurity.prevalence,
           group = 1, fill = "States")) +
  geom_bar(stat="identity", width = 0.8) +
  coord_flip() + 
  theme_ipsum() + 
  scale_x_discrete(guide = guide_axis(angle = 10)) +
  geom_text(aes(label = Food.insecurity.prevalence),
            colour = "white",
            size = 2.4,
            vjust =0.45,
            hjust = 1.2, 
            position = position_dodge(0.1)
) +
labs(title = "Food Insecurity Status By State",
      subtitle = "From 2020  to  2022  ",
      y= "Food Insecurity Prevalence",
      x = "States") +
  theme(axis.title = element_text(family = "Helvetica",
                                  size = (20),
                                  colour = "steelblue4",
                                  face = "bold.italic"),
                                  plot.title = element_text(family ="Helvetica", size = (20), colour = "steelblue4", face = "bold.italic"),
        plot.subtitle = element_text(family = "Helvetica",
        size = (12), colour = "lightblue3",
        face = "bold.italic"))

poverty <- read.csv("poverty.csv") |>
           rename(below_pov = X2022.Percent.below.poverty.level) 
poverty$state <- state.abb[match(poverty$State,state.name)]
poverty <- poverty |> na.omit() 
states_fs <- states_fs |> rename(state = State)
pov_an <- inner_join(poverty, states_fs) |>
          rename(fip = Food.insecurity.prevalence) |>
          select(state, fip, below_pov)
## Joining with `by = join_by(state)`

Poverty vs Food Security per State Analysis

As the poverty is higher, we see that there’s more insecurity.

cc<-ggplot(data = pov_an) +
  geom_point(mapping = aes(x=state, y=below_pov, color = fip, size = fip)) +
  labs(
    title = "The Effect of Poverty on Food Security",
  ) +
    theme_minimal() +
  
  theme(
    plot.title = element_text(color = "#0099f9", size = 20, face = "bold", hjust = 0.5),
    plot.subtitle = element_text(size = 13, face = "bold", hjust = 0.5),
    plot.caption = element_text(face = "italic", hjust = 0),
    panel.border = element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    axis.text.x = element_text(size = 10, face = "bold", angle = 60, hjust=1)  
  ) + 
  ylab("Percent Below Poverty Level") +
  xlab("State") + 
 scale_color_continuous(limits=c(1, 7), breaks=seq(1, 7, by=1)) +
   guides(color= guide_legend(title = "Food Insecurity Prevalence"), size=guide_legend(title = "Food Insecurity Prevalence")) 

cc + 
  scale_color_gradient(name = "fip", low = "#ffff00", high = "#8b0000") 
## Scale for colour is already present.
## Adding another scale for colour, which will replace the existing scale.