Healthy Cities GIS Assignment

Author

Gerardo Sandoval

Load the libraries and set the working directory

library(tidyverse)
library(tidyr)
library(leaflet)
setwd("/Users/gerardosandoval/Downloads")
cities500 <- read_csv("500CitiesLocalHealthIndicators.cdc.csv")

The GeoLocation variable has (lat, long) format

Split GeoLocation (lat, long) into two columns: lat and long

latlong <- cities500|>
  mutate(GeoLocation = str_replace_all(GeoLocation, "[()]", ""))|>
  separate(GeoLocation, into = c("lat", "long"), sep = ",", convert = TRUE)
head(latlong)
# A tibble: 6 × 25
   Year StateAbbr StateDesc  CityName  GeographicLevel DataSource Category      
  <dbl> <chr>     <chr>      <chr>     <chr>           <chr>      <chr>         
1  2017 CA        California Hawthorne Census Tract    BRFSS      Health Outcom…
2  2017 CA        California Hawthorne City            BRFSS      Unhealthy Beh…
3  2017 CA        California Hayward   City            BRFSS      Health Outcom…
4  2017 CA        California Hayward   City            BRFSS      Unhealthy Beh…
5  2017 CA        California Hemet     City            BRFSS      Prevention    
6  2017 CA        California Indio     Census Tract    BRFSS      Health Outcom…
# ℹ 18 more variables: UniqueID <chr>, Measure <chr>, Data_Value_Unit <chr>,
#   DataValueTypeID <chr>, Data_Value_Type <chr>, Data_Value <dbl>,
#   Low_Confidence_Limit <dbl>, High_Confidence_Limit <dbl>,
#   Data_Value_Footnote_Symbol <chr>, Data_Value_Footnote <chr>,
#   PopulationCount <dbl>, lat <dbl>, long <dbl>, CategoryID <chr>,
#   MeasureId <chr>, CityFIPS <dbl>, TractFIPS <dbl>, Short_Question_Text <chr>

Filter the dataset

Remove the StateDesc that includes the United Sates, select Prevention as the category (of interest), filter for only measuring crude prevalence and select only 2017.

latlong_clean <- latlong |>
  filter(StateDesc != "United States") |>
  filter(Category == "Prevention") |>
  filter(Data_Value_Type == "Crude prevalence") |>
  filter(Year == 2017)
head(latlong_clean)
# A tibble: 6 × 25
   Year StateAbbr StateDesc  CityName   GeographicLevel DataSource Category  
  <dbl> <chr>     <chr>      <chr>      <chr>           <chr>      <chr>     
1  2017 AL        Alabama    Montgomery City            BRFSS      Prevention
2  2017 CA        California Concord    City            BRFSS      Prevention
3  2017 CA        California Concord    City            BRFSS      Prevention
4  2017 CA        California Fontana    City            BRFSS      Prevention
5  2017 CA        California Richmond   Census Tract    BRFSS      Prevention
6  2017 FL        Florida    Davie      Census Tract    BRFSS      Prevention
# ℹ 18 more variables: UniqueID <chr>, Measure <chr>, Data_Value_Unit <chr>,
#   DataValueTypeID <chr>, Data_Value_Type <chr>, Data_Value <dbl>,
#   Low_Confidence_Limit <dbl>, High_Confidence_Limit <dbl>,
#   Data_Value_Footnote_Symbol <chr>, Data_Value_Footnote <chr>,
#   PopulationCount <dbl>, lat <dbl>, long <dbl>, CategoryID <chr>,
#   MeasureId <chr>, CityFIPS <dbl>, TractFIPS <dbl>, Short_Question_Text <chr>

What variables are included? (can any of them be removed?)

names(latlong_clean)
 [1] "Year"                       "StateAbbr"                 
 [3] "StateDesc"                  "CityName"                  
 [5] "GeographicLevel"            "DataSource"                
 [7] "Category"                   "UniqueID"                  
 [9] "Measure"                    "Data_Value_Unit"           
[11] "DataValueTypeID"            "Data_Value_Type"           
[13] "Data_Value"                 "Low_Confidence_Limit"      
[15] "High_Confidence_Limit"      "Data_Value_Footnote_Symbol"
[17] "Data_Value_Footnote"        "PopulationCount"           
[19] "lat"                        "long"                      
[21] "CategoryID"                 "MeasureId"                 
[23] "CityFIPS"                   "TractFIPS"                 
[25] "Short_Question_Text"       

Remove the variables that will not be used in the assignment

prevention <- latlong_clean |>
  select(-DataSource,-Data_Value_Unit, -DataValueTypeID, -Low_Confidence_Limit, -High_Confidence_Limit, -Data_Value_Footnote_Symbol, -Data_Value_Footnote)
head(prevention)
# A tibble: 6 × 18
   Year StateAbbr StateDesc  CityName  GeographicLevel Category UniqueID Measure
  <dbl> <chr>     <chr>      <chr>     <chr>           <chr>    <chr>    <chr>  
1  2017 AL        Alabama    Montgome… City            Prevent… 151000   Choles…
2  2017 CA        California Concord   City            Prevent… 616000   Visits…
3  2017 CA        California Concord   City            Prevent… 616000   Choles…
4  2017 CA        California Fontana   City            Prevent… 624680   Visits…
5  2017 CA        California Richmond  Census Tract    Prevent… 0660620… Choles…
6  2017 FL        Florida    Davie     Census Tract    Prevent… 1216475… Choles…
# ℹ 10 more variables: Data_Value_Type <chr>, Data_Value <dbl>,
#   PopulationCount <dbl>, lat <dbl>, long <dbl>, CategoryID <chr>,
#   MeasureId <chr>, CityFIPS <dbl>, TractFIPS <dbl>, Short_Question_Text <chr>
md <- prevention |>
  filter(StateAbbr=="MD")
head(md)
# A tibble: 6 × 18
   Year StateAbbr StateDesc CityName  GeographicLevel Category  UniqueID Measure
  <dbl> <chr>     <chr>     <chr>     <chr>           <chr>     <chr>    <chr>  
1  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Chole…
2  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Visit…
3  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Visit…
4  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Curre…
5  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Curre…
6  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Visit…
# ℹ 10 more variables: Data_Value_Type <chr>, Data_Value <dbl>,
#   PopulationCount <dbl>, lat <dbl>, long <dbl>, CategoryID <chr>,
#   MeasureId <chr>, CityFIPS <dbl>, TractFIPS <dbl>, Short_Question_Text <chr>

The new dataset “Prevention” is a manageable dataset now.

For your assignment, work with the cleaned “Prevention” dataset

1. Once you run the above code, filter this dataset one more time for any particular subset.

Filter chunk here

unique(latlong_clean$StateAbbr)
 [1] "AL" "CA" "FL" "CT" "IL" "MN" "NY" "PA" "NC" "OH" "OK" "OR" "TX" "RI" "SC"
[16] "SD" "TN" "UT" "VA" "WA" "AK" "WI" "AZ" "AR" "CO" "DE" "NV" "DC" "GA" "ID"
[31] "HI" "MA" "MI" "IN" "KS" "KY" "IA" "LA" "MD" "ME" "NH" "NJ" "NM" "MO" "MS"
[46] "NE" "MT" "ND" "WV" "VT" "WY"
prevention2 <- prevention %>%
  filter(StateDesc == "Rhode Island") %>%
  filter (Short_Question_Text == "Annual Checkup")
  prevention2
# A tibble: 103 × 18
    Year StateAbbr StateDesc  CityName GeographicLevel Category UniqueID Measure
   <dbl> <chr>     <chr>      <chr>    <chr>           <chr>    <chr>    <chr>  
 1  2017 RI        Rhode Isl… Pawtuck… Census Tract    Prevent… 4454640… Visits…
 2  2017 RI        Rhode Isl… Warwick  Census Tract    Prevent… 4474300… Visits…
 3  2017 RI        Rhode Isl… Pawtuck… Census Tract    Prevent… 4454640… Visits…
 4  2017 RI        Rhode Isl… Cranston Census Tract    Prevent… 4419180… Visits…
 5  2017 RI        Rhode Isl… Provide… Census Tract    Prevent… 4459000… Visits…
 6  2017 RI        Rhode Isl… Pawtuck… Census Tract    Prevent… 4454640… Visits…
 7  2017 RI        Rhode Isl… Provide… Census Tract    Prevent… 4459000… Visits…
 8  2017 RI        Rhode Isl… Provide… Census Tract    Prevent… 4459000… Visits…
 9  2017 RI        Rhode Isl… Warwick  Census Tract    Prevent… 4474300… Visits…
10  2017 RI        Rhode Isl… Warwick  City            Prevent… 4474300  Visits…
# ℹ 93 more rows
# ℹ 10 more variables: Data_Value_Type <chr>, Data_Value <dbl>,
#   PopulationCount <dbl>, lat <dbl>, long <dbl>, CategoryID <chr>,
#   MeasureId <chr>, CityFIPS <dbl>, TractFIPS <dbl>, Short_Question_Text <chr>

2. Based on the GIS tutorial (Japan earthquakes), create one plot about something in your subsetted dataset.

First plot chunk here

prevention3 <- prevention %>%
  filter (Short_Question_Text == "Taking BP Medication")
  prevention3
# A tibble: 28,504 × 18
    Year StateAbbr StateDesc  CityName GeographicLevel Category UniqueID Measure
   <dbl> <chr>     <chr>      <chr>    <chr>           <chr>    <chr>    <chr>  
 1  2017 NY        New York   Schenec… Census Tract    Prevent… 3665508… Taking…
 2  2017 NC        North Car… Cary     Census Tract    Prevent… 3710740… Taking…
 3  2017 NC        North Car… Durham   Census Tract    Prevent… 3719000… Taking…
 4  2017 NC        North Car… Gastonia Census Tract    Prevent… 3725580… Taking…
 5  2017 NC        North Car… Greensb… Census Tract    Prevent… 3728000… Taking…
 6  2017 OH        Ohio       Columbus Census Tract    Prevent… 3918000… Taking…
 7  2017 OK        Oklahoma   Norman   Census Tract    Prevent… 4052500… Taking…
 8  2017 OK        Oklahoma   Oklahom… Census Tract    Prevent… 4055000… Taking…
 9  2017 OK        Oklahoma   Oklahom… Census Tract    Prevent… 4055000… Taking…
10  2017 OR        Oregon     Gresham  Census Tract    Prevent… 4131250… Taking…
# ℹ 28,494 more rows
# ℹ 10 more variables: Data_Value_Type <chr>, Data_Value <dbl>,
#   PopulationCount <dbl>, lat <dbl>, long <dbl>, CategoryID <chr>,
#   MeasureId <chr>, CityFIPS <dbl>, TractFIPS <dbl>, Short_Question_Text <chr>
ggplot(prevention3, aes(x = StateDesc, y = Data_Value, fill = StateDesc)) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = c(
    "California" = "skyblue",
    "New York" = "purple",
    "Texas" = "forestgreen",
    "Florida" = "red"
    )) +
  theme_minimal() +
  labs(
    title = "Blood Pressure Per State",
    x = "State",
    y = "Blood Pressure" ,
    ) + 
  theme(axis.text.x = element_text(angle = 90, hjust = 1))
Warning: Removed 794 rows containing missing values or values outside the scale range
(`geom_bar()`).

3. Now create a map of your subsetted dataset.

First map chunk here

leaflet(prevention2) |>
  setView(lng = -71.4459, lat = 41.8222, zoom = 11) |>
  addProviderTiles("Stadia.AlidadeSmooth") |>
  addCircles(
    data = prevention2,
    radius = prevention2$Data_Value,
    color = "hotpink",
    fillColor = "pink",
    fillOpacity = 0.50
)
Assuming "long" and "lat" are longitude and latitude, respectively

4. Refine your map to include a mousover tooltip

Refined map chunk here

popupprev <- paste0(
"<b>City: </b>", prevention2$CityName, "<br>", 
"<b>Population: </b>", prevention2$PopulationCount, "<br>", 
"<b>Reason: </b>", prevention2$Short_Question_Text, "<br>", 
"<b>Percentage of People who Visited: </b>", prevention2$Data_Value, "<br>" 
)
map2 <-leaflet() |>
  setView(lng = -71.4459, lat = 41.8222, zoom =11) |>
  addProviderTiles("Stadia.AlidadeSmooth") |>
  addCircles(
    data = prevention2,
    radius = prevention2$Data_Value,
    color = "hotpink",
    fillColor = "pink",
    fillOpacity = 0.50 ,
    popup = popupprev
    )
Assuming "long" and "lat" are longitude and latitude, respectively
map2

5. Write a paragraph

Due to the limited number of numerical variables in the data set, I decided to use a bar graph for my first visualization. It clearly shows that states with higher populations and more known cities tend to have higher blood pressure (BP) levels. Possible reasons for this could include a higher prevalence of fast food restaurants and lower quality food availability. For my second visualization, I used a map to display the percentage of people who have their annual checkup at specific locations. The data appears to be focused in the northern part of Rhode Island, but more information is needed to understand why.