Healthy Cities GIS Assignment

Author

Walter Hinkley

Load the libraries and set the working directory

library(leaflet)
library(sf)
library(tidyverse)
library(tidyr)
setwd("~/Desktop/Data Science 110")
cities500 <- read_csv("500CitiesLocalHealthIndicators.cdc.csv")
data(cities500)

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>
unique(md$CityName)
[1] "Baltimore"

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

usa_lon <- -98.35
usa_lat <- 39.50

For your assignment, work with a cleaned dataset.

1. Once you run the above code, filter this dataset one more time for any particular subset with no more than 900 observations.

Filter chunk here

new <- latlong |>
  filter(StateDesc != "United States") |>
  filter(Short_Question_Text == "Coronary Heart Disease") |>
  filter(GeographicLevel == "City") |>
  filter(Data_Value >= "4.2")|>
  filter(Year == "2017")
head(new)
# A tibble: 6 × 25
   Year StateAbbr StateDesc  CityName     GeographicLevel DataSource Category   
  <dbl> <chr>     <chr>      <chr>        <chr>           <chr>      <chr>      
1  2017 CA        California Hayward      City            BRFSS      Health Out…
2  2017 AL        Alabama    Huntsville   City            BRFSS      Health Out…
3  2017 AZ        Arizona    Surprise     City            BRFSS      Health Out…
4  2017 CA        California Bellflower   City            BRFSS      Health Out…
5  2017 CA        California Garden Grove City            BRFSS      Health Out…
6  2017 CA        California Roseville    City            BRFSS      Health Out…
# ℹ 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>
new2 <- new|>
  select(-StateAbbr, -DataSource, -DataValueTypeID, -Data_Value_Footnote_Symbol, -Data_Value_Footnote, -MeasureId, -TractFIPS)
head(new2)
# A tibble: 6 × 18
   Year StateDesc  CityName     GeographicLevel Category        UniqueID Measure
  <dbl> <chr>      <chr>        <chr>           <chr>           <chr>    <chr>  
1  2017 California Hayward      City            Health Outcomes 633000   Corona…
2  2017 Alabama    Huntsville   City            Health Outcomes 137000   Corona…
3  2017 Arizona    Surprise     City            Health Outcomes 471510   Corona…
4  2017 California Bellflower   City            Health Outcomes 604982   Corona…
5  2017 California Garden Grove City            Health Outcomes 629000   Corona…
6  2017 California Roseville    City            Health Outcomes 662938   Corona…
# ℹ 11 more variables: Data_Value_Unit <chr>, Data_Value_Type <chr>,
#   Data_Value <dbl>, Low_Confidence_Limit <dbl>, High_Confidence_Limit <dbl>,
#   PopulationCount <dbl>, lat <dbl>, long <dbl>, CategoryID <chr>,
#   CityFIPS <dbl>, Short_Question_Text <chr>
chd <- new2
head(chd)
# A tibble: 6 × 18
   Year StateDesc  CityName     GeographicLevel Category        UniqueID Measure
  <dbl> <chr>      <chr>        <chr>           <chr>           <chr>    <chr>  
1  2017 California Hayward      City            Health Outcomes 633000   Corona…
2  2017 Alabama    Huntsville   City            Health Outcomes 137000   Corona…
3  2017 Arizona    Surprise     City            Health Outcomes 471510   Corona…
4  2017 California Bellflower   City            Health Outcomes 604982   Corona…
5  2017 California Garden Grove City            Health Outcomes 629000   Corona…
6  2017 California Roseville    City            Health Outcomes 662938   Corona…
# ℹ 11 more variables: Data_Value_Unit <chr>, Data_Value_Type <chr>,
#   Data_Value <dbl>, Low_Confidence_Limit <dbl>, High_Confidence_Limit <dbl>,
#   PopulationCount <dbl>, lat <dbl>, long <dbl>, CategoryID <chr>,
#   CityFIPS <dbl>, Short_Question_Text <chr>

Coronary heart disease (CHD), also known as coronary artery disease (CAD) or ischemic heart disease, occurs when the coronary arteries narrow or become blocked, preventing the heart from receiving enough oxygen-rich blood

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

First plot chunk here

ggplot(chd, aes(x=Data_Value, y=PopulationCount, color=Data_Value_Type))+
  geom_point(alpha = 0.01)+
  scale_color_viridis_d()+
  geom_jitter()+
  labs(title = "CHD % based on Population Count")+
  theme_dark()

3. Now create a map of your subsetted dataset.

First map chunk here

leaflet() |>
  setView(lng = -98.35, lat = 39.50, zoom =4) |>
  addProviderTiles("Esri.WorldStreetMap") |>
  addCircles(
    data = chd,
    fillOpacity = 0.1,
    radius = chd$Data_Value)
Assuming "long" and "lat" are longitude and latitude, respectively

4. Refine your map to include a mouse-click tooltip

Refined map chunk here

chdpop <- paste0(
  "<b>City: </b>", chd$CityName, "<br>",
      "<b>State: </b>", chd$StateDesc, "<br>",
      "<b>Population: </b>", chd$PopulationCount, "<br>",
      "<b>CHD %: </b>", chd$Data_Value, "<br>"
)
leaflet() |>
  setView(lng = -98.35, lat = 39.5, zoom =4) |>
  addProviderTiles("Esri.WorldStreetMap") |>
  addCircles(
    data = chd,
    fillOpacity = 0.5,
    popup = chdpop,
    radius = sqrt(10^chd$Data_Value)*2)
Assuming "long" and "lat" are longitude and latitude, respectively

5. Write a paragraph

In a paragraph, describe the plots you created and what they show.

I have cleaned the 500 cities data set down to cases of Coronary Heart diesease. I have plotted the cases and made a map of cities that have cases over 4.2 percent. The cities or areas with larger diameter circles have larger percentage of people with high coronary heart disease. The locations with the highest percentages are Gary Indiana, Largo Florida, and Hemet California, all with 9% or higher.