Healthy Cities GIS Assignment

Author

Charlie Roth

Load the libraries and set the working directory

library(tidyverse)
library(tidyr)
setwd("/Users/allisonroth/Downloads/DATA 110")
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>
app <- prevention |>
  filter(StateAbbr %in% c("AL", "GA", "KY", "MD", "MS", "NY", "NC", "OH", "PA", "SC", "TN", "VA", "WV"))
head(app)
# A tibble: 6 × 18
   Year StateAbbr StateDesc   CityName GeographicLevel Category UniqueID Measure
  <dbl> <chr>     <chr>       <chr>    <chr>           <chr>    <chr>    <chr>  
1  2017 AL        Alabama     Montgom… City            Prevent… 151000   "Chole…
2  2017 NY        New York    Buffalo  Census Tract    Prevent… 3611000… "Chole…
3  2017 PA        Pennsylvan… Philade… Census Tract    Prevent… 4260000… "Chole…
4  2017 NY        New York    Rochest… Census Tract    Prevent… 3663000… "Curre…
5  2017 NY        New York    Rochest… Census Tract    Prevent… 3663000… "Visit…
6  2017 NY        New York    Rochest… Census Tract    Prevent… 3663000… "Chole…
# ℹ 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

I filtered for MeasureId = “BPMED” which is taking blood pressure medication.

app2 <- app |>
  filter(MeasureId == "BPMED")
head(app2)
# A tibble: 6 × 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 Caro… Cary     Census Tract    Prevent… 3710740… Taking…
3  2017 NC        North Caro… Durham   Census Tract    Prevent… 3719000… Taking…
4  2017 NC        North Caro… Gastonia Census Tract    Prevent… 3725580… Taking…
5  2017 NC        North Caro… Greensb… Census Tract    Prevent… 3728000… Taking…
6  2017 OH        Ohio        Columbus Census Tract    Prevent… 3918000… Taking…
# ℹ 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

app3 <- app2 |>
  group_by(StateDesc) |>
  filter(!is.na(Data_Value) & !is.na(PopulationCount) & PopulationCount < 1000000) # I filtered out populations over 1 million which removed New York City and Philadelphia.
options(scipen = 999)
ggplot(app3, aes(Data_Value, PopulationCount, color = StateDesc)) +
  geom_point() +
  theme_classic() +
  scale_color_manual(values = c("#dcb79d", "#969f83", "#6c2132", "#bb2034", "#252c30", "#cf5f14", "#e5ac3b", "#842c5c", "#704021", "#cf807a", "#474c32", "#8e0f1d", "#495112")) +
  facet_wrap(~StateDesc) +
  labs(title = "Data Value vs Population Count for the 13 Appalachian States",
       y = "Population Count",
       x = "Data Value",
       color = "States")

3. Now create a map of your subsetted dataset.

First map chunk here

I created a new data set grouping by CityName, StateAbbr, StateDesc, and Data_Value_Type. It includes the year, the data value for each city, the population count for each city, and the longitude and latitude for each city. I did this to use for my maps so there’s only one dot for each city.

app4 <- app2 |>
  group_by(CityName, StateAbbr, StateDesc, Data_Value_Type) |>
  summarise(
    Year = mean(Year),
    Data_Value = mean(Data_Value),
    PopulationCount = sum(PopulationCount),
    lat = median(lat),
    long = median(long)
  )
`summarise()` has grouped output by 'CityName', 'StateAbbr', 'StateDesc'. You
can override using the `.groups` argument.
app4
# A tibble: 84 × 9
# Groups:   CityName, StateAbbr, StateDesc [84]
   CityName StateAbbr StateDesc Data_Value_Type  Year Data_Value PopulationCount
   <chr>    <chr>     <chr>     <chr>           <dbl>      <dbl>           <dbl>
 1 Akron    OH        Ohio      Crude prevalen…  2017       NA            398220
 2 Albany   GA        Georgia   Crude prevalen…  2017       76.9          154868
 3 Albany   NY        New York  Crude prevalen…  2017       70.2          195712
 4 Alexand… VA        Virginia  Crude prevalen…  2017       69.3          279932
 5 Allento… PA        Pennsylv… Crude prevalen…  2017       73.8          236064
 6 Ashevil… NC        North Ca… Crude prevalen…  2017       NA            166786
 7 Athens   GA        Georgia   Crude prevalen…  2017       67.1          230904
 8 Atlanta  GA        Georgia   Crude prevalen…  2017       NA            840006
 9 Augusta  GA        Georgia   Crude prevalen…  2017       78.0          391688
10 Baltimo… MD        Maryland  Crude prevalen…  2017       NA           1241922
# ℹ 74 more rows
# ℹ 2 more variables: lat <dbl>, long <dbl>
library(leaflet)
leaflet() |>
  setView(lng = -81.08, lat = 36.91, zoom = 5) |>
  addProviderTiles("OpenStreetMap.HOT") |>
  addCircles(
    data = app4,
    radius = (app4$Data_Value^3)/10,
    color = "#8017f5",
    fillColor = "#cda4fb",
    fillOpacity = 0.5
  )
Assuming "long" and "lat" are longitude and latitude, respectively

4. Refine your map to include a mousover tooltip

Refined map chunk here

popupapp <- paste0(
      "<b>City Name: </b>", app4$CityName, "<br>",
      "<b>State: </b>", app4$StateDesc, "<br>",
      "<b>Data Value: </b>", app4$Data_Value, "<br>",
      "<b>Population: </b>", app4$PopulationCount, "<br>"
    )
leaflet() |>
  setView(lng = -81.08, lat = 36.91, zoom = 5) |>
  addProviderTiles("OpenStreetMap.HOT") |>
  addCircles(
    data = app4,
    radius = (app4$Data_Value^3)/10,
    color = "#8017f5",
    fillColor = "#cda4fb",
    fillOpacity = .5,
    popup = popupapp
  )
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.

The first plot I made shows 13 different scatter plots with Data Value on the x axis and Population Count on the y axis. Each plot is for the 13 Appalachian States, Alabama, Georgia, Kentucky, Maryland, Mississippi, New York, North Carolina, Ohio, Pennsylvania, South Carolina, Tennessee, Virginia, and West Virginia. All of the plots showed that the population would increase when data value was around 75. Both maps I made show bubbles that represent cities in the 13 states. The size of the bubble shows the data value. The second map has a tooltip that shows the city Name, state, data Value, and population.