\[Libraries & Data\]

library(readr)
## Warning: package 'readr' was built under R version 4.3.2
library(plotly)
## Warning: package 'plotly' was built under R version 4.3.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.3.2
## 
## 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(tidyverse)
## Warning: package 'tidyr' was built under R version 4.3.2
## Warning: package 'purrr' was built under R version 4.3.2
## Warning: package 'dplyr' was built under R version 4.3.2
## Warning: package 'stringr' was built under R version 4.3.2
## Warning: package 'lubridate' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ stringr   1.5.1
## ✔ forcats   1.0.0     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks plotly::filter(), stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
data= read.csv("C:/Users/Chafiaa/Downloads/Food security.csv")
head(data)
##   X State Year POVALL_2021 PCTPOVALL_2021 POV017_2021 PCTPOV017_2021
## 1 0    AL 2021      800848           16.3      250327           22.7
## 2 1    AK 2021       77736           10.8       23760           13.5
## 3 2    AZ 2021      919680           12.9      281696           17.8
## 4 3    AR 2021      471195           16.0      150353           21.8
## 5 4    CA 2021     4742405           12.3     1362903           15.8
## 6 5    CO 2021      554126            9.7      144163           11.8
##   POV517_2021 PCTPOV517_2021 MEDHHINC_2021 POV04_2021 PCTPOV04_2021
## 1      176596           21.6         53990      71220          25.1
## 2       16316           12.7         78437       6633          14.1
## 3      197841           16.7         68967      76649          19.7
## 4      102718           20.1         52577      45096          25.5
## 5      993484           15.4         84831     339169          15.8
## 6       99663           10.9         82228      39308          12.8
##   OverallFoodInsecurityRate SeniorFoodInsecurityRate.StateofSeniorHunger.
## 1                     0.148                                         0.089
## 2                     0.107                                         0.084
## 3                     0.103                                         0.074
## 4                     0.155                                         0.076
## 5                     0.105                                         0.074
## 6                     0.092                                         0.074
##   X.ofFoodInsecureSeniors.StateofSeniorHunger.
## 1                                       103567
## 2                                        12149
## 3                                       129412
## 4                                        55600
## 5                                       620899
## 6                                       102243
##   OlderAdultFoodInsecurityRate.StateofSeniorHunger.
## 1                                             0.144
## 2                                             0.080
## 3                                             0.085
## 4                                             0.198
## 5                                             0.104
## 6                                             0.082
##   X.ofFoodInsecureOlderAdults.StateofSeniorHunger. ChildFoodInsecurityRate
## 1                                           100289                   0.183
## 2                                             6184                   0.128
## 3                                            79721                   0.140
## 4                                            75302                   0.191
## 5                                           485709                   0.135
## 6                                            55579                   0.105
##   X.ofFoodInsecureChildren
## 1                   204830
## 2                    22960
## 3                   226080
## 4                   134690
## 5                  1182720
## 6                   129900

\[Food\ insecurity \ by\ state\]

state_bp <- ggplot(data, aes(x=reorder(State, OverallFoodInsecurityRate), y=OverallFoodInsecurityRate, fill=State)) + 
  geom_col() + theme_minimal() + coord_flip()
state_bp <- state_bp + theme(legend.position="none") 
state_bp <- state_bp + theme(text = element_text(size=8), axis.title=element_text(size=12)) 
state_bp <- state_bp + labs(title = "Food Insecurity by State", x= "State", y= "Food Insecurity rate")
state_bp <- state_bp + theme(plot.title = element_text(size=8))
state_bp

## From the plot "Food Insecurity by State" we can see the highest rate of poverty is Mississippi, Arizona, Alabama, Texas

\[Poverty\ Rate\ by\ State\]

map <- plot_geo(data, locationmode = 'USA-states') %>%
  add_trace(
    z = ~POVALL_2021,
    locations = ~State,
    color = ~POVALL_2021,
    colorscale = 'purple',
    colorbar = list(title = 'Poverty_Rate (%)')
  ) %>%
  layout(
    title = 'US Poverty Rate in 2021',
    geo = list(scope = 'usa')
  )

map
## Warning: Ignoring 102 observations
##From the plot "US Poverty Rate in 2021" the states with the highest poverty rate is CA and Texas, Arizona, ...etc

\[From \ the \ two\ plots\ above\ I\ can\ say\ that\ the \ states \ with\ highest\ poverty\ rate \ has\ food \ insecurity \] \[Correlation\ between\ poverty \ rate\ and\ food\ insecurity\]

ggplot(data, aes(x = POVALL_2021, y = OverallFoodInsecurityRate)) +
  geom_point(color = "blue") +
  geom_smooth(method = "lm", formula = y ~ x, se = FALSE, color = "red") +  
  geom_abline(intercept = 0, slope = 0, linetype = "dashed", color = "black") +  
  labs(x = "Poverty Rate", y = "Food Insecurity ", title = "Correlation between Poverty Rate and Food Insecurity Prevalence") 
## Warning: Removed 102 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 102 rows containing missing values (`geom_point()`).

from the correlation plot we can confirm the conclusion on my first 2 plots, poverty lead to food insecurity.

\[Food\ insecurite\ on \ US \ by \ Age\]

plot_ly(data, x = ~State, y = ~SeniorFoodInsecurityRate.StateofSeniorHunger., color = ~SeniorFoodInsecurityRate.StateofSeniorHunger.
, type = 'scatter', mode = 'lines') %>%
  layout(title = "Food Insecurity-Seniors",
         xaxis = list(title = "State", tickangle = 35),
         yaxis = list(title = "Food Insecurity Rate"),
         legend = list(title = "Senior age"),
         margin = list(l = 45, r = 45, b = 45, t = 45))
## Warning: line.color doesn't (yet) support data arrays

## Warning: line.color doesn't (yet) support data arrays
plot_ly(data, x = ~State, y = ~ChildFoodInsecurityRate
, color = ~ChildFoodInsecurityRate
, type = 'scatter', mode = 'lines') %>%
  layout(title = "Food Insecurity-Children",
         xaxis = list(title = "State", tickangle = 35), 
         yaxis = list(title = "Food Insecurity Rate"),
         legend = list(title = "Children age"),
         margin = list(l = 45, r = 45, b = 45, t = 45)) 
## Warning: line.color doesn't (yet) support data arrays

## Warning: line.color doesn't (yet) support data arrays
plot_ly(data, x = ~State, y = ~OlderAdultFoodInsecurityRate.StateofSeniorHunger.
, color = ~OlderAdultFoodInsecurityRate.StateofSeniorHunger.

, type = 'scatter', mode = 'lines') %>%
  layout(title = "Food Insecurity-Adults",
         xaxis = list(title = "State", tickangle = 35), 
         yaxis = list(title = "Food Insecurity Rate"),
         legend = list(title = "Adults age"),
         margin = list(l = 45, r = 45, b = 45, t = 45)) 
## Warning: line.color doesn't (yet) support data arrays

## Warning: line.color doesn't (yet) support data arrays

##From the 03 plot of food insecurity by age we see that children suffering from food insecurity then adults but senior citizen have less rate of food insecurity .

##Conclusion: Food insecurity is related to poverty, unfortunately in the USA children suffer more from food insecurity and adults come in the second place because a lot of adults have expensive housing bills, medical bills and unemoployment problems which lead to poverty and less money to spend to feed them self and their children but senior citizen we see them in better place because they get some discounts on medical bills (Medicaid), social security and most of them their children grow up and left the household.