Food security is the ability to have consistent physical and financial access to the safe, healthy, and nutritious foods required for human development. There are typically three components of food security - food availability, food access, and nutrient access. Availability refers to the adequate and reliable supply of food, while food access pertains to the resources required to procure food. The nutrient access component of food security involves getting adequate nutrients from food. Consuming healthy, nutritious foods offers protection against some of the leading causes of death in the United States including heart disease (Sharkey 2009).

This project uses data from the United States Department of Agriculture (USDA)’s Food Access Research Atlas (FARA) database, which contains information about several indicators for food access based on demographics and socioeconomic factors. The USDA measures access using distance to stores or by number of stores, as well as individual resources (income, car) and neighborhood level resources (public transportation). The original data set includes over 100 variables but for this project the variables in the table below were those considered for analysis. Most of the variables used for this project relate to distance as opposed to resources.

Table1: Description of variables
Variable Description
Census tract Numeric, Census tract code
State Character, State name
County Character, name of county
Urban Numeric, Indicator for whether the tract is an urban tract
POP2010 Numeric, Tract population in 2010
Pov ertyRate Numeric, Share of the population living below the federal poverty rate.
Medi anFami lyIncome Numeric, Median family income for the tract

lapop1,

lap op1share

Numeric, Number of people with low access (at 1 mile )

Share of people with low access (at 1 mile )

lalowi1,

lalo wi1share

Numeric, Number of low-income people with lowaccess | (at 1 mile) | | Numeric, Share of low -income people with low access (at 1 mile ) |

lakids1,

laki ds1share

Numeric, Number of children age 0 -17 with low access (at 1 mile )

Numeric, Share of children age 0-17 with low access (at 1 mile )

las eniors1, l asenio rs1share

Numeric, Number of seniors age 65+ with low access (at 1 mile )

Numeric, Share of seniors age 65+ with low access (at 1 mile )

l awhite1, lawhi te1share

Numeric, Number of White people with low access (at 1 mile )

Numeric, Share of White people with low access (at 1 mile )

l ablack1,

labla ck1share

Numeric, Number of Black people with low access (at 1 mile )

Numeric, Share of Black people with low access (at 1 mile )

l aasian1,

laasi an1share

Numeric, Number of Asian people with low access (at 1 mile )

Numeric, Share of Asian people with low access (at 1 mile )

l anhopi1, lanho pi1share

Numeric, Number of Native Hawaiian or Other Pacific Islanders with low access (at 1 mile )

Numeric, Share of Native Hawaiian or Other Pacific Islanders with low access (at 1 mile )

laaian1,

laai an1share

Numeric, Number of American Indian or Alaska Native people with low access (at 1 mile )

Numeric, Share of American Indian or Alaska Native people with low access (at 1 mile )

lao multir1,

l aomult ir1share

Numeric, Number of other or multiracial people with low access (at 1 mile )

Numeric, Share of Native other or multiracial people with low access (at 1 mile )

lahisp1,

lahi sp1share

Numeric, Number of Hispanic people with low access (at 1 mile )

Numeric, Share of Hispanic people with low access (at 1 mile )

lahunv1,

lahu nv1share

Numeric, Number of people without vehicles and with low access (at 1 mile )

Numeric, Share of people without vehicles and with low access (at 1 mile )

lasnap1,

lasn ap1share

Numeric, Number of SNAP households with low access (at 1 mile )

Numeric, Share of SNAP households with low access (at 1 mile )

Loading libraries

library(RColorBrewer)
library(tidyverse)
library(corrplot)
library(leaflet)
library(leaflegend)
library(sf)
library(highcharter)

Reading in the data

df <- read_csv("food_access_research.csv")
View(df)

Cleaning the data

names(df) <- tolower(names(df)) #making all headers lower case
names(df) <- gsub(" ","",names(df)) #removing spaces between header names
head(df)
## # A tibble: 6 × 147
##   censustract state county urban pop2010 ohu2010 group…¹ numgq…² pctgq…³ lilat…⁴
##         <dbl> <chr> <chr>  <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
## 1  1001020100 Alab… Autau…     1    1912     693       0       0  0            0
## 2  1001020200 Alab… Autau…     1    2170     743       0     181  0.0834       0
## 3  1001020300 Alab… Autau…     1    3373    1256       0       0  0            0
## 4  1001020400 Alab… Autau…     1    4386    1722       0       0  0            0
## 5  1001020500 Alab… Autau…     1   10766    4082       0     181  0.0168       0
## 6  1001020600 Alab… Autau…     1    3668    1311       0       0  0            0
## # … with 137 more variables: lilatracts_halfand10 <dbl>,
## #   lilatracts_1and20 <dbl>, lilatracts_vehicle <dbl>, hunvflag <dbl>,
## #   lowincometracts <dbl>, povertyrate <dbl>, medianfamilyincome <dbl>,
## #   la1and10 <dbl>, lahalfand10 <dbl>, la1and20 <dbl>, latracts_half <dbl>,
## #   latracts1 <dbl>, latracts10 <dbl>, latracts20 <dbl>,
## #   latractsvehicle_20 <dbl>, lapop1_10 <dbl>, lapop05_10 <dbl>,
## #   lapop1_20 <dbl>, lalowi1_10 <dbl>, lalowi05_10 <dbl>, lalowi1_20 <dbl>, …

The data set required minimal cleaning. Any cleaning involved transforming the names of variables from upper to lower case.

Checking variable names

names(df)
##   [1] "censustract"          "state"                "county"              
##   [4] "urban"                "pop2010"              "ohu2010"             
##   [7] "groupquartersflag"    "numgqtrs"             "pctgqtrs"            
##  [10] "lilatracts_1and10"    "lilatracts_halfand10" "lilatracts_1and20"   
##  [13] "lilatracts_vehicle"   "hunvflag"             "lowincometracts"     
##  [16] "povertyrate"          "medianfamilyincome"   "la1and10"            
##  [19] "lahalfand10"          "la1and20"             "latracts_half"       
##  [22] "latracts1"            "latracts10"           "latracts20"          
##  [25] "latractsvehicle_20"   "lapop1_10"            "lapop05_10"          
##  [28] "lapop1_20"            "lalowi1_10"           "lalowi05_10"         
##  [31] "lalowi1_20"           "lapophalf"            "lapophalfshare"      
##  [34] "lalowihalf"           "lalowihalfshare"      "lakidshalf"          
##  [37] "lakidshalfshare"      "laseniorshalf"        "laseniorshalfshare"  
##  [40] "lawhitehalf"          "lawhitehalfshare"     "lablackhalf"         
##  [43] "lablackhalfshare"     "laasianhalf"          "laasianhalfshare"    
##  [46] "lanhopihalf"          "lanhopihalfshare"     "laaianhalf"          
##  [49] "laaianhalfshare"      "laomultirhalf"        "laomultirhalfshare"  
##  [52] "lahisphalf"           "lahisphalfshare"      "lahunvhalf"          
##  [55] "lahunvhalfshare"      "lasnaphalf"           "lasnaphalfshare"     
##  [58] "lapop1"               "lapop1share"          "lalowi1"             
##  [61] "lalowi1share"         "lakids1"              "lakids1share"        
##  [64] "laseniors1"           "laseniors1share"      "lawhite1"            
##  [67] "lawhite1share"        "lablack1"             "lablack1share"       
##  [70] "laasian1"             "laasian1share"        "lanhopi1"            
##  [73] "lanhopi1share"        "laaian1"              "laaian1share"        
##  [76] "laomultir1"           "laomultir1share"      "lahisp1"             
##  [79] "lahisp1share"         "lahunv1"              "lahunv1share"        
##  [82] "lasnap1"              "lasnap1share"         "lapop10"             
##  [85] "lapop10share"         "lalowi10"             "lalowi10share"       
##  [88] "lakids10"             "lakids10share"        "laseniors10"         
##  [91] "laseniors10share"     "lawhite10"            "lawhite10share"      
##  [94] "lablack10"            "lablack10share"       "laasian10"           
##  [97] "laasian10share"       "lanhopi10"            "lanhopi10share"      
## [100] "laaian10"             "laaian10share"        "laomultir10"         
## [103] "laomultir10share"     "lahisp10"             "lahisp10share"       
## [106] "lahunv10"             "lahunv10share"        "lasnap10"            
## [109] "lasnap10share"        "lapop20"              "lapop20share"        
## [112] "lalowi20"             "lalowi20share"        "lakids20"            
## [115] "lakids20share"        "laseniors20"          "laseniors20share"    
## [118] "lawhite20"            "lawhite20share"       "lablack20"           
## [121] "lablack20share"       "laasian20"            "laasian20share"      
## [124] "lanhopi20"            "lanhopi20share"       "laaian20"            
## [127] "laaian20share"        "laomultir20"          "laomultir20share"    
## [130] "lahisp20"             "lahisp20share"        "lahunv20"            
## [133] "lahunv20share"        "lasnap20"             "lasnap20share"       
## [136] "tractlowi"            "tractkids"            "tractseniors"        
## [139] "tractwhite"           "tractblack"           "tractasian"          
## [142] "tractnhopi"           "tractaian"            "tractomultir"        
## [145] "tracthispanic"        "tracthunv"            "tractsnap"

Removing the variables that will not be used

This project will focus on the state of Maryland, where I currently reside. It will use the variables with information about the census tract, county, urban/rural designation, population, poverty rate, and several variables about the share of specific population groups living more than one mile from the nearest supermarket, supercenter, or large grocery store by age, race, and ethnicity. I chose the 1 mile variable because that is usually the distance used to classify areas as food deserts although this is typically used for urban areas.

df2 <- df|> 
  filter(state == "Maryland") |>
  select(censustract, state, county, urban, pop2010, povertyrate, medianfamilyincome,'lapop1':'lasnap1share')
head(df2)
## # A tibble: 6 × 33
##   censustract state  county urban pop2010 pover…¹ media…² lapop1 lapop…³ lalowi1
##         <dbl> <chr>  <chr>  <dbl>   <dbl>   <dbl>   <dbl>  <dbl>   <dbl>   <dbl>
## 1 24001000100 Maryl… Alleg…     0    3718     6.6   56875 3718.   1       1079. 
## 2 24001000200 Maryl… Alleg…     0    4564    13.7   60943 4553.   0.997   1667. 
## 3 24001000300 Maryl… Alleg…     0    2780    20.2   42727 1959.   0.705    575. 
## 4 24001000400 Maryl… Alleg…     1    3022    12.8   48831 1513.   0.501    600. 
## 5 24001000500 Maryl… Alleg…     1    2734    56     34519  905.   0.331    472. 
## 6 24001000600 Maryl… Alleg…     1    2965    12.6   53438   58.0  0.0196    20.9
## # … with 23 more variables: lalowi1share <dbl>, lakids1 <dbl>,
## #   lakids1share <dbl>, laseniors1 <dbl>, laseniors1share <dbl>,
## #   lawhite1 <dbl>, lawhite1share <dbl>, lablack1 <dbl>, lablack1share <dbl>,
## #   laasian1 <dbl>, laasian1share <dbl>, lanhopi1 <dbl>, lanhopi1share <dbl>,
## #   laaian1 <dbl>, laaian1share <dbl>, laomultir1 <dbl>, laomultir1share <dbl>,
## #   lahisp1 <dbl>, lahisp1share <dbl>, lahunv1 <dbl>, lahunv1share <dbl>,
## #   lasnap1 <dbl>, lasnap1share <dbl>, and abbreviated variable names …

Exploring the relationship between the variables

cormat <- cor(df2[ ,4:33])
round(cormat,2)
##                    urban pop2010 povertyrate medianfamilyincome lapop1
## urban               1.00    0.04        0.17              -0.02  -0.44
## pop2010             0.04    1.00       -0.15               0.22   0.46
## povertyrate         0.17   -0.15        1.00              -0.62  -0.28
## medianfamilyincome -0.02    0.22       -0.62               1.00   0.32
## lapop1             -0.44    0.46       -0.28               0.32   1.00
## lapop1share        -0.56    0.15       -0.32               0.30   0.88
## lalowi1            -0.34    0.35        0.06              -0.02   0.71
## lalowi1share       -0.46    0.06        0.01              -0.07   0.61
## lakids1            -0.41    0.44       -0.32               0.36   0.95
## lakids1share       -0.50    0.17       -0.34               0.35   0.86
## laseniors1         -0.51    0.31       -0.28               0.30   0.86
## laseniors1share    -0.58    0.04       -0.28               0.26   0.70
## lawhite1           -0.52    0.39       -0.26               0.29   0.92
## lawhite1share      -0.62    0.11       -0.29               0.27   0.79
## lablack1           -0.03    0.25       -0.12               0.10   0.49
## lablack1share      -0.06    0.09       -0.12               0.09   0.42
## laasian1            0.02    0.35       -0.15               0.39   0.48
## laasian1share       0.01    0.21       -0.23               0.45   0.44
## lanhopi1           -0.13    0.23       -0.09               0.11   0.47
## lanhopi1share      -0.14    0.04       -0.10               0.08   0.33
## laaian1            -0.35    0.31       -0.21               0.19   0.73
## laaian1share       -0.41    0.05       -0.21               0.15   0.57
## laomultir1         -0.18    0.42       -0.18               0.25   0.76
## laomultir1share    -0.23    0.16       -0.20               0.22   0.63
## lahisp1            -0.14    0.39       -0.18               0.25   0.67
## lahisp1share       -0.18    0.14       -0.21               0.23   0.55
## lahunv1            -0.25    0.25        0.03              -0.01   0.55
## lahunv1share       -0.27    0.06        0.05              -0.04   0.45
## lasnap1            -0.34    0.24        0.03              -0.10   0.58
## lasnap1share       -0.39    0.05        0.05              -0.12   0.49
##                    lapop1share lalowi1 lalowi1share lakids1 lakids1share
## urban                    -0.56   -0.34        -0.46   -0.41        -0.50
## pop2010                   0.15    0.35         0.06    0.44         0.17
## povertyrate              -0.32    0.06         0.01   -0.32        -0.34
## medianfamilyincome        0.30   -0.02        -0.07    0.36         0.35
## lapop1                    0.88    0.71         0.61    0.95         0.86
## lapop1share               1.00    0.60         0.74    0.84         0.96
## lalowi1                   0.60    1.00         0.82    0.56         0.54
## lalowi1share              0.74    0.82         1.00    0.53         0.67
## lakids1                   0.84    0.56         0.53    1.00         0.89
## lakids1share              0.96    0.54         0.67    0.89         1.00
## laseniors1                0.83    0.54         0.56    0.81         0.77
## laseniors1share           0.87    0.48         0.65    0.64         0.78
## lawhite1                  0.82    0.64         0.56    0.87         0.79
## lawhite1share             0.91    0.54         0.67    0.75         0.87
## lablack1                  0.43    0.36         0.32    0.47         0.42
## lablack1share             0.46    0.31         0.37    0.40         0.45
## laasian1                  0.33    0.33         0.14    0.46         0.36
## laasian1share             0.39    0.20         0.14    0.47         0.44
## lanhopi1                  0.40    0.43         0.35    0.44         0.41
## lanhopi1share             0.39    0.28         0.36    0.32         0.41
## laaian1                   0.67    0.51         0.49    0.72         0.67
## laaian1share              0.70    0.42         0.56    0.56         0.68
## laomultir1                0.63    0.65         0.52    0.74         0.65
## laomultir1share           0.69    0.51         0.60    0.64         0.71
## lahisp1                   0.56    0.56         0.44    0.65         0.57
## lahisp1share              0.61    0.43         0.50    0.55         0.62
## lahunv1                   0.50    0.65         0.63    0.50         0.48
## lahunv1share              0.52    0.60         0.72    0.40         0.50
## lasnap1                   0.55    0.71         0.76    0.56         0.54
## lasnap1share              0.60    0.65         0.85    0.46         0.57
##                    laseniors1 laseniors1share lawhite1 lawhite1share lablack1
## urban                   -0.51           -0.58    -0.52         -0.62    -0.03
## pop2010                  0.31            0.04     0.39          0.11     0.25
## povertyrate             -0.28           -0.28    -0.26         -0.29    -0.12
## medianfamilyincome       0.30            0.26     0.29          0.27     0.10
## lapop1                   0.86            0.70     0.92          0.79     0.49
## lapop1share              0.83            0.87     0.82          0.91     0.43
## lalowi1                  0.54            0.48     0.64          0.54     0.36
## lalowi1share             0.56            0.65     0.56          0.67     0.32
## lakids1                  0.81            0.64     0.87          0.75     0.47
## lakids1share             0.77            0.78     0.79          0.87     0.42
## laseniors1               1.00            0.89     0.87          0.82     0.28
## laseniors1share          0.89            1.00     0.73          0.87     0.21
## lawhite1                 0.87            0.73     1.00          0.89     0.12
## lawhite1share            0.82            0.87     0.89          1.00     0.06
## lablack1                 0.28            0.21     0.12          0.06     1.00
## lablack1share            0.24            0.25     0.07          0.07     0.93
## laasian1                 0.31            0.20     0.36          0.23     0.20
## laasian1share            0.33            0.27     0.33          0.28     0.19
## lanhopi1                 0.32            0.24     0.40          0.32     0.29
## lanhopi1share            0.23            0.22     0.27          0.30     0.21
## laaian1                  0.58            0.49     0.62          0.54     0.48
## laaian1share             0.49            0.55     0.48          0.58     0.39
## laomultir1               0.53            0.40     0.57          0.45     0.55
## laomultir1share          0.48            0.48     0.47          0.50     0.48
## lahisp1                  0.47            0.35     0.51          0.40     0.45
## lahisp1share             0.42            0.41     0.42          0.45     0.39
## lahunv1                  0.53            0.47     0.48          0.42     0.33
## lahunv1share             0.44            0.50     0.40          0.45     0.27
## lasnap1                  0.54            0.48     0.51          0.48     0.36
## lasnap1share             0.47            0.54     0.43          0.52     0.31
##                    lablack1share laasian1 laasian1share lanhopi1 lanhopi1share
## urban                      -0.06     0.02          0.01    -0.13         -0.14
## pop2010                     0.09     0.35          0.21     0.23          0.04
## povertyrate                -0.12    -0.15         -0.23    -0.09         -0.10
## medianfamilyincome          0.09     0.39          0.45     0.11          0.08
## lapop1                      0.42     0.48          0.44     0.47          0.33
## lapop1share                 0.46     0.33          0.39     0.40          0.39
## lalowi1                     0.31     0.33          0.20     0.43          0.28
## lalowi1share                0.37     0.14          0.14     0.35          0.36
## lakids1                     0.40     0.46          0.47     0.44          0.32
## lakids1share                0.45     0.36          0.44     0.41          0.41
## laseniors1                  0.24     0.31          0.33     0.32          0.23
## laseniors1share             0.25     0.20          0.27     0.24          0.22
## lawhite1                    0.07     0.36          0.33     0.40          0.27
## lawhite1share               0.07     0.23          0.28     0.32          0.30
## lablack1                    0.93     0.20          0.19     0.29          0.21
## lablack1share               1.00     0.14          0.17     0.26          0.26
## laasian1                    0.14     1.00          0.92     0.24          0.12
## laasian1share               0.17     0.92          1.00     0.21          0.16
## lanhopi1                    0.26     0.24          0.21     1.00          0.87
## lanhopi1share               0.26     0.12          0.16     0.87          1.00
## laaian1                     0.44     0.25          0.24     0.43          0.34
## laaian1share                0.45     0.14          0.19     0.36          0.40
## laomultir1                  0.47     0.56          0.51     0.56          0.43
## laomultir1share             0.51     0.39          0.45     0.52          0.55
## lahisp1                     0.38     0.57          0.53     0.51          0.41
## lahisp1share                0.41     0.40          0.47     0.49          0.54
## lahunv1                     0.30     0.18          0.14     0.22          0.16
## lahunv1share                0.31     0.13          0.12     0.20          0.20
## lasnap1                     0.33     0.07          0.06     0.29          0.21
## lasnap1share                0.35     0.03          0.04     0.25          0.24
##                    laaian1 laaian1share laomultir1 laomultir1share lahisp1
## urban                -0.35        -0.41      -0.18           -0.23   -0.14
## pop2010               0.31         0.05       0.42            0.16    0.39
## povertyrate          -0.21        -0.21      -0.18           -0.20   -0.18
## medianfamilyincome    0.19         0.15       0.25            0.22    0.25
## lapop1                0.73         0.57       0.76            0.63    0.67
## lapop1share           0.67         0.70       0.63            0.69    0.56
## lalowi1               0.51         0.42       0.65            0.51    0.56
## lalowi1share          0.49         0.56       0.52            0.60    0.44
## lakids1               0.72         0.56       0.74            0.64    0.65
## lakids1share          0.67         0.68       0.65            0.71    0.57
## laseniors1            0.58         0.49       0.53            0.48    0.47
## laseniors1share       0.49         0.55       0.40            0.48    0.35
## lawhite1              0.62         0.48       0.57            0.47    0.51
## lawhite1share         0.54         0.58       0.45            0.50    0.40
## lablack1              0.48         0.39       0.55            0.48    0.45
## lablack1share         0.44         0.45       0.47            0.51    0.38
## laasian1              0.25         0.14       0.56            0.39    0.57
## laasian1share         0.24         0.19       0.51            0.45    0.53
## lanhopi1              0.43         0.36       0.56            0.52    0.51
## lanhopi1share         0.34         0.40       0.43            0.55    0.41
## laaian1               1.00         0.89       0.68            0.62    0.57
## laaian1share          0.89         1.00       0.54            0.65    0.45
## laomultir1            0.68         0.54       1.00            0.88    0.95
## laomultir1share       0.62         0.65       0.88            1.00    0.84
## lahisp1               0.57         0.45       0.95            0.84    1.00
## lahisp1share          0.52         0.55       0.83            0.94    0.89
## lahunv1               0.44         0.36       0.47            0.42    0.39
## lahunv1share          0.37         0.41       0.40            0.44    0.32
## lasnap1               0.52         0.44       0.49            0.46    0.38
## lasnap1share          0.45         0.48       0.42            0.49    0.32
##                    lahisp1share lahunv1 lahunv1share lasnap1 lasnap1share
## urban                     -0.18   -0.25        -0.27   -0.34        -0.39
## pop2010                    0.14    0.25         0.06    0.24         0.05
## povertyrate               -0.21    0.03         0.05    0.03         0.05
## medianfamilyincome         0.23   -0.01        -0.04   -0.10        -0.12
## lapop1                     0.55    0.55         0.45    0.58         0.49
## lapop1share                0.61    0.50         0.52    0.55         0.60
## lalowi1                    0.43    0.65         0.60    0.71         0.65
## lalowi1share               0.50    0.63         0.72    0.76         0.85
## lakids1                    0.55    0.50         0.40    0.56         0.46
## lakids1share               0.62    0.48         0.50    0.54         0.57
## laseniors1                 0.42    0.53         0.44    0.54         0.47
## laseniors1share            0.41    0.47         0.50    0.48         0.54
## lawhite1                   0.42    0.48         0.40    0.51         0.43
## lawhite1share              0.45    0.42         0.45    0.48         0.52
## lablack1                   0.39    0.33         0.27    0.36         0.31
## lablack1share              0.41    0.30         0.31    0.33         0.35
## laasian1                   0.40    0.18         0.13    0.07         0.03
## laasian1share              0.47    0.14         0.12    0.06         0.04
## lanhopi1                   0.49    0.22         0.20    0.29         0.25
## lanhopi1share              0.54    0.16         0.20    0.21         0.24
## laaian1                    0.52    0.44         0.37    0.52         0.45
## laaian1share               0.55    0.36         0.41    0.44         0.48
## laomultir1                 0.83    0.47         0.40    0.49         0.42
## laomultir1share            0.94    0.42         0.44    0.46         0.49
## lahisp1                    0.89    0.39         0.32    0.38         0.32
## lahisp1share               1.00    0.33         0.34    0.35         0.36
## lahunv1                    0.33    1.00         0.91    0.71         0.66
## lahunv1share               0.34    0.91         1.00    0.65         0.73
## lasnap1                    0.35    0.71         0.65    1.00         0.91
## lasnap1share               0.36    0.66         0.73    0.91         1.00
head(cormat)
##                          urban    pop2010 povertyrate medianfamilyincome
## urban               1.00000000  0.0380657   0.1680852        -0.01908392
## pop2010             0.03806570  1.0000000  -0.1519863         0.21517124
## povertyrate         0.16808525 -0.1519863   1.0000000        -0.61947627
## medianfamilyincome -0.01908392  0.2151712  -0.6194763         1.00000000
## lapop1             -0.44330511  0.4550113  -0.2753147         0.31747959
## lapop1share        -0.55669301  0.1461004  -0.3166914         0.30252510
##                        lapop1 lapop1share     lalowi1 lalowi1share    lakids1
## urban              -0.4433051  -0.5566930 -0.34022553 -0.464757058 -0.4091009
## pop2010             0.4550113   0.1461004  0.34655566  0.060190666  0.4385748
## povertyrate        -0.2753147  -0.3166914  0.05588075  0.008224374 -0.3176813
## medianfamilyincome  0.3174796   0.3025251 -0.02063065 -0.066830433  0.3598268
## lapop1              1.0000000   0.8775051  0.71312486  0.607471365  0.9488460
## lapop1share         0.8775051   1.0000000  0.60283762  0.737365481  0.8406497
##                    lakids1share laseniors1 laseniors1share   lawhite1
## urban                -0.5039947 -0.5054084     -0.57938067 -0.5199987
## pop2010               0.1666688  0.3145763      0.04134984  0.3892956
## povertyrate          -0.3368997 -0.2846580     -0.27525918 -0.2592248
## medianfamilyincome    0.3472498  0.3000163      0.25515859  0.2886624
## lapop1                0.8583633  0.8571541      0.70231475  0.9166337
## lapop1share           0.9624090  0.8264645      0.86979385  0.8182822
##                    lawhite1share    lablack1 lablack1share    laasian1
## urban                 -0.6214724 -0.03239693   -0.05758382  0.01510228
## pop2010                0.1086502  0.24636340    0.08697370  0.35036321
## povertyrate           -0.2906460 -0.11952802   -0.12411657 -0.15041813
## medianfamilyincome     0.2681394  0.10249649    0.09127756  0.39454048
## lapop1                 0.7862070  0.49379454    0.41590360  0.47862536
## lapop1share            0.9124224  0.42802999    0.45956183  0.32791759
##                    laasian1share    lanhopi1 lanhopi1share    laaian1
## urban                0.005889507 -0.13312038   -0.13598813 -0.3451375
## pop2010              0.213831207  0.23323311    0.04387869  0.3137083
## povertyrate         -0.225693397 -0.08735749   -0.09963795 -0.2122954
## medianfamilyincome   0.453078946  0.11119586    0.08180701  0.1879422
## lapop1               0.438692194  0.47137661    0.32509147  0.7253720
## lapop1share          0.393564279  0.40067542    0.38696111  0.6665306
##                    laaian1share laomultir1 laomultir1share    lahisp1
## urban               -0.40746946 -0.1780470      -0.2330517 -0.1361257
## pop2010              0.05464767  0.4229322       0.1552561  0.3898301
## povertyrate         -0.21076655 -0.1774272      -0.2021138 -0.1847488
## medianfamilyincome   0.14689938  0.2459762       0.2198722  0.2512668
## lapop1               0.57087023  0.7577883       0.6271132  0.6719426
## lapop1share          0.69727405  0.6294006       0.6886288  0.5585869
##                    lahisp1share     lahunv1 lahunv1share     lasnap1
## urban                -0.1827602 -0.25000064  -0.27023432 -0.33937388
## pop2010               0.1416371  0.24759987   0.06066048  0.24165460
## povertyrate          -0.2118854  0.02667358   0.05471197  0.02862185
## medianfamilyincome    0.2296010 -0.01167732  -0.04043540 -0.09944419
## lapop1                0.5505293  0.54624850   0.44958836  0.57643443
## lapop1share           0.6064201  0.49688290   0.52479364  0.55249002
##                    lasnap1share
## urban               -0.39025719
## pop2010              0.04713623
## povertyrate          0.04527654
## medianfamilyincome  -0.11993416
## lapop1               0.48579637
## lapop1share          0.59705800
corrplot(cormat, method = "color", cl.pos = 'b')

The correlation matrix shows a strong positive correlation between the share of the population with low food access and the following variables: the share of children, seniors, and white population with low access. The variable for urban designation also shows a moderate negative correction with the following variables: the population share, seniors and the white population. These will be explored further.

##Explore the relationshiop between quantitative and categorical variables

#Creating boxplot of share of people with low access at 1 mile by tract type
ggplot(df2, aes(x = factor(urban), y = lapop1share, fill=factor(urban)))+
  geom_boxplot(outlier.colour = "red", outlier.shape = 20)+
  labs(fill="Tract Type", title = "Share of people with low access (at 1 mile) by tract type", x="Tract Type", y="Share of people with low access", caption = "Data Source: USDA Food Access Research Atlas")+
  scale_x_discrete(labels=c("Rural", "Urban"))+
  scale_fill_brewer(palette = "Dark2", labels=c("Rural","Urban"))

##Creating boxplot of share of seniors with low access at 1 mile by tract type
ggplot(df2, aes(x = factor(urban), y = laseniors1share, fill=factor(urban)))+
  geom_boxplot(outlier.colour = "red", outlier.shape = 20)+
  labs(fill="Tract Type", title = "Share of seniors age 65+ with low access (at 1 mile) by tract type", x="Tract Type", y="Share of seniors age 65+ with low access", caption = "Data Source: USDA Food Access Research Atlas")+
  scale_x_discrete(labels=c("Rural", "Urban"))+
  scale_fill_brewer(palette = "Dark2", labels=c("Rural","Urban"))

##Creating boxplot of share of white people with low access at 1 mile by tract type
ggplot(df2, aes(x = factor(urban), y = lawhite1share, fill=factor(urban)))+
  geom_boxplot(outlier.colour = "red", outlier.shape = 20)+
  labs(fill="Tract Type", title = "Share of white people with low access (at 1 mile) by tract type", x="Tract Type", y="Share of white people with low access", caption = "Data Source: USDA Food Access Research Atlas")+
  scale_x_discrete(labels=c("Rural", "Urban"))+
  scale_fill_brewer(palette = "Dark2", labels=c("Rural","Urban"))

The box plots show that the share of all people, seniors, and white people with low food access is higher in rural census tracts. It should be noted that there are many more urban than rural census tracts in the state of Maryland. The box plots also show several outliers which will be retained for this project.

Exploring relationship between lapop1share and other variables

ggplot(df2, 
       aes(x = lapop1share, 
           y = lakids1share, color=factor(Urban))) +
  geom_point(color="red") +
  geom_smooth(se=FALSE, 
              method="lm",
              color = "grey") +
  labs(x = "Share of population with low access",
       y="Share of children with low access",
       title = "Share of children age 0 -17 with low access versus share of population with low access (at 1 mile), 2010", caption = "Data Source: USDA Food Access Research Atlas") +
  theme_minimal() 

ggplot(df2, 
       aes(x = lapop1share, 
           y = laseniors1share, color=factor(Urban))) +
  geom_point(color="red") +
  geom_smooth(se=FALSE, 
              method="lm",
              color = "grey") +
  labs(x = "Share of population with low access",
       y="Share of seniors with low access",
       title = "Share of seniors age 65+ with low access versus share of population with low access (at 1 mile), 2010", caption = "Data Source: USDA Food Access Research Atlas") +
  theme_minimal() 

ggplot(df2, 
       aes(x = lapop1share, 
           y = lawhite1share, color=factor(Urban))) +
  geom_point(color="red") +
  geom_smooth(se=FALSE, 
              method="lm",
              color = "grey") +
  labs(x = "Share of population with low access",
       y="Share of white people with low access",
       title = "Share of white people with low access versus share of population with low access (at 1 mile), 2010", caption = "Data Source: USDA Food Access Research Atlas") +
  theme_minimal() 

The scatter plots indicate that the share of children age 0 -17, seniors age 65+, and white people with low access increases with increasing share of the population with low access which intuitively makes sense. The next visualization will look at the share of children and the share of the population with low access.

Creating a map with the share of the population and children with low access (at 1 mile).

#Importing and transforming shapefile data for Maryland and calculating centroid of the counties in Maryland
data_map <- read_sf("gz_2010_24_140_00_500k.shp")
data_map <- sf::st_as_sf(data_map)
data_map <- st_transform(data_map, crs = '+proj=longlat +datum=WGS84')|>
separate(GEO_ID, into = c("censustract1", "censustract"), sep = "US")|>
  mutate(centroids = st_centroid(st_geometry(data_map)))
data_map$censustract <- as.numeric(data_map$censustract)

View(data_map)

#joining the data file with the data file and pulling out the centroids. 
join_data<- inner_join(df2,data_map)|>
  separate(centroids, into = c("lon", "lat"), 
                 sep= "\\((\\-?\\d+\\.\\d+) (\\-?\\d+\\.\\d+)\\)", 
                 remove = FALSE)
View(join_data)



#converting share of the different demographic groups to percentage
join_data <-join_data |>
  mutate_at(vars(contains('share')), function(x) x*100)|>
  mutate_at(vars(contains('share')), round, 2)
  


## creating a color palette for the map
pal1 <- colorNumeric(
  palette = "YlGn",
  domain = join_data$lapop1share)
pal2 <- colorNumeric(
  palette = "OrRd",
  domain = join_data$lakids1share)


#creating a popup for the counties
popupmd<- paste0("<b>County: </b>", join_data$county, "<br>", 
                 "<b>Population: </b>",  join_data$pop2010, "<br>", 
                 "<b>Median Income: $</b>", join_data$medianfamilyincome, "<br>", 
                 "<b>Poverty Rate: </b>", join_data$povertyrate, "% </b>","<br>",
                 "<b>Population w/ low access: </b>", join_data$lapop1share, "% </b>","<br>",
                 "<b>Children w/ low access: </b>", join_data$lakids1share, "% </b>","<br>")

#creating  a popup for the centroids
popupcentroid<- paste0("<b>County: </b>", join_data$county , "<br>",
                 "<b>Low-income people w/ low access: </b>", join_data$lalowi1share, "% </b>", "<br>",
                 "<b>Seniors age 65+ w/ low access: </b>", join_data$laseniors1share, "% </b>","<br>",
                 "<b>White people w/ low access: </b>", join_data$lawhite1share, "% </b>","<br>",
                 "<b>Black people  w/ low access: </b>", join_data$lablack1share, "% </b>","<br>",
                 "<b>Asian people w/ low access: </b>", join_data$laasian1share, "% </b>","<br>",
                 "<b>Native Hawaiian/Other Pacific Islander popilation w/ low access: </b>", join_data$lanhopi1share, "% </b>","<br>",
                 "<b>American Indian/Alaska Native people w/ low access : </b>", join_data$laaian1share, "% </b>","<br>",
                 "<b>Other/Multiracial people w/ low access : </b>", join_data$laomultir1share, "% </b>","<br>",
                 "<b>Hispanic people w/ low access : </b>", join_data$lahisp1share, "% </b>","<br>",
                 "<b>Housing units w/ no vehicle access and w/ low access : </b>", join_data$lahunv1share, "% </b>","<br>",
                 "<b>SNAP households w/ low access : </b>", join_data$lasnap1share, "% </b>","<br>")


#Creating the map
leaflet(st_as_sf(join_data)) |>
  setView(lng = -76.641273, lat = 39.045753, zoom = 6) |>
  addProviderTiles(provider = "Esri.WorldStreetMap")|>
  addPolygons( 
              stroke = FALSE,
              smoothFactor = 0.2, 
              fillColor = pal1(join_data$lapop1share),
              fillOpacity = 1, 
              popup=popupmd)|>
      addCircleMarkers(
        data=join_data$centroids,     
        radius = 3, 
             weight = 0.2, 
             fillColor = pal2(join_data$lakids1share),
        fillOpacity = 11,
        popup=popupcentroid)|>
    addLegend("bottomright", pal = pal1, values = ~lapop1share,
    title = "People with low access, 2010",
    labFormat = labelFormat(suffix = "%"),
    opacity = 1)|>
    addLegend("bottomright", pal = pal2, values = ~lakids1share,
    title = "Children with low access, 2010",
    labFormat = labelFormat(suffix = "%"),
    opacity = 1)

The map above shows the share of the population and children age 0-17 within a census tract in the State of Maryland living more than one mile form the nearest supermarket, supercenter, or large grocery store in 2010. Specifically, the colors of the census tracts represent the share of the population with low access while the colors for the circles represent the share of children. Clicking within the county or on the centroid will provide additional socioeconomic and demographic information about the census tract.

What stands out clearly in this visualization is the number of census tracts with 80% or more of the people living more than a mile from a store. The map also clearly shows the correlation between the share of people living more than a mile from a food store and the children living more than a mile within a food store.

I would have liked to find information about food sources in 2010 and add the locations of those as markers as that would provide more information about the issue of food access. For further analysis, I would also like to examine how food access changes based on the ethnic group that makes up the majority of the people within the census tract.

Works cited

Sharkey, J. R. (2009). Measuring potential access to food stores and food-service places in rural areas in the US. American journal of preventive medicine, 36(4), S151-S155.