Healthy Cities GIS Assignment

Author

Your Name

Load the libraries and set the working directory

library(tidyverse)
library(tidyr)
library(leaflet)
setwd("/Users/kidusteffera/Desktop/DATA110/week 10")
cities500 <- read_csv("500CitiesLocalHealthIndicators.cdc (1).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) |>
  mutate(lat = as.numeric(lat),
         long = as.numeric(long))
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(Data_Value_Type == "Crude prevalence") |>
  filter(Year == 2017) |>
  filter(StateAbbr == "MT") |>
  filter(CityName == "Missoula") |>
  filter(Category == "Health Outcomes")
head(latlong_clean)
# A tibble: 6 × 25
   Year StateAbbr StateDesc CityName GeographicLevel DataSource Category       
  <dbl> <chr>     <chr>     <chr>    <chr>           <chr>      <chr>          
1  2017 MT        Montana   Missoula City            BRFSS      Health Outcomes
2  2017 MT        Montana   Missoula Census Tract    BRFSS      Health Outcomes
3  2017 MT        Montana   Missoula Census Tract    BRFSS      Health Outcomes
4  2017 MT        Montana   Missoula Census Tract    BRFSS      Health Outcomes
5  2017 MT        Montana   Missoula Census Tract    BRFSS      Health Outcomes
6  2017 MT        Montana   Missoula Census Tract    BRFSS      Health Outcomes
# ℹ 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

latlong_clean2 <- latlong_clean |>
  select(-DataSource, -Data_Value_Unit, -DataValueTypeID,
         -Low_Confidence_Limit, -High_Confidence_Limit,
         -Data_Value_Footnote_Symbol, -Data_Value_Footnote)
head(latlong_clean2)
# A tibble: 6 × 18
   Year StateAbbr StateDesc CityName GeographicLevel Category   UniqueID Measure
  <dbl> <chr>     <chr>     <chr>    <chr>           <chr>      <chr>    <chr>  
1  2017 MT        Montana   Missoula City            Health Ou… 3050200  Chroni…
2  2017 MT        Montana   Missoula Census Tract    Health Ou… 3050200… Stroke…
3  2017 MT        Montana   Missoula Census Tract    Health Ou… 3050200… Arthri…
4  2017 MT        Montana   Missoula Census Tract    Health Ou… 3050200… Physic…
5  2017 MT        Montana   Missoula Census Tract    Health Ou… 3050200… High c…
6  2017 MT        Montana   Missoula Census Tract    Health Ou… 3050200… Corona…
# ℹ 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 “latlong_clean2” is a manageable dataset now.

For your assignment, work with a cleaned dataset where you perform your own cleaning and filtering.

1. Once you run the above code and filter this complicated dataset, perform your own investigation by filtering this dataset however you choose so that you have a subset with no more than 900 observations through some inclusion/exclusion criteria.

Filter chunk here (you may need multiple chunks)

missoula_tracts <- latlong_clean2 |>
  filter(GeographicLevel == "Census Tract") |>
  filter(Short_Question_Text %in% c("Obesity", "Diabetes",
                                    "High Blood Pressure",
                                    "COPD",
                                    "Coronary Heart Disease")) |>
  filter(!is.na(lat), !is.na(long), !is.na(Data_Value))

nrow(missoula_tracts)
[1] 64
head(missoula_tracts)
# A tibble: 6 × 18
   Year StateAbbr StateDesc CityName GeographicLevel Category   UniqueID Measure
  <dbl> <chr>     <chr>     <chr>    <chr>           <chr>      <chr>    <chr>  
1  2017 MT        Montana   Missoula Census Tract    Health Ou… 3050200… Corona…
2  2017 MT        Montana   Missoula Census Tract    Health Ou… 3050200… High b…
3  2017 MT        Montana   Missoula Census Tract    Health Ou… 3050200… Diagno…
4  2017 MT        Montana   Missoula Census Tract    Health Ou… 3050200… High b…
5  2017 MT        Montana   Missoula Census Tract    Health Ou… 3050200… Corona…
6  2017 MT        Montana   Missoula Census Tract    Health Ou… 3050200… High b…
# ℹ 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>
missoula_tracts |>
  count(Short_Question_Text)
# A tibble: 4 × 2
  Short_Question_Text        n
  <chr>                  <int>
1 COPD                      16
2 Coronary Heart Disease    16
3 Diabetes                  16
4 High Blood Pressure       16

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

First plot chunk here

ggplot(missoula_tracts,
       aes(x = reorder(Short_Question_Text, Data_Value, median),
           y = Data_Value,
           fill = Short_Question_Text)) +
  geom_boxplot(alpha = 0.8, show.legend = FALSE) +
  geom_jitter(width = 0.15, alpha = 0.4, size = 1.2) +
  coord_flip() +
  labs(title = "Chronic Health Outcomes Across Missoula Census Tracts (2017)",
       subtitle = "Crude prevalence (%), one point per census tract",
       x = NULL,
       y = "Crude prevalence (%)",
       caption = "Source: CDC 500 Cities Local Health Indicators") +
  theme_minimal(base_size = 12)

3. Now create a map of your subsetted dataset.

First map chunk here

missoula_obesity <- missoula_tracts |>
  filter(Short_Question_Text == "Obesity")

pal <- colorNumeric(palette = "YlOrRd", domain = missoula_obesity$Data_Value)

leaflet(missoula_obesity) |>
  addTiles() |>
  addCircleMarkers(
    lng = ~long,
    lat = ~lat,
    radius = ~Data_Value / 3,
    color = ~pal(Data_Value),
    fillOpacity = 0.7,
    stroke = FALSE
  ) |>
  addLegend("bottomright", pal = pal, values = ~Data_Value,
            title = "Obesity (%)", opacity = 1)
Warning in min(x): no non-missing arguments to min; returning Inf
Warning in max(x): no non-missing arguments to max; returning -Inf

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

Refined map chunk here

leaflet(missoula_obesity) |>
  addProviderTiles(providers$CartoDB.Positron) |>
  addCircleMarkers(
    lng = ~long,
    lat = ~lat,
    radius = ~Data_Value / 3,
    color = ~pal(Data_Value),
    fillOpacity = 0.75,
    stroke = TRUE,
    weight = 1,
    popup = ~paste0(
      "<b>Census Tract:</b> ", TractFIPS, "<br/>",
      "<b>Obesity (crude prevalence):</b> ", Data_Value, "%<br/>",
      "<b>Population:</b> ", PopulationCount
    ),
    label = ~paste0("Obesity: ", Data_Value, "%")
  ) |>
  addLegend("bottomright", pal = pal, values = ~Data_Value,
            title = "Obesity (%)", opacity = 1) |>
  setView(lng = -114.01, lat = 46.87, zoom = 12)
Warning in min(x): no non-missing arguments to min; returning Inf
Warning in max(x): no non-missing arguments to max; returning -Inf

5. Write a paragraph

The analysis presented here was focused upon the city of Missoula, Montana, and utilized the CDC 500 Cities Local Health Indicators for 2017 at the census-tract level. After filtering for the city of Missoula, the crude prevalence data, and only the five chronic health conditions, the resulting subset of the dataset exists well below the 900 observation limit that exists within the dataset, yet contains sufficient variation within both geographic and health-related factors to examine.

Within the boxplot that demonstrates the prevalence of each of the five chronic conditions within Missoula, both high blood pressure and obesity are depicted as the most prevalent of the five groups of conditions, residing within the mid-20s to low-30s percent range of prevalence within the census tracts of Missoula. In contrast, conditions like coronary heart disease and COPD are much less common within the population of Missoula, with prevalence rates of only single digits. Furthermore, the prevalence within each of the census tracts of Missoula ranges from the lowest prevalence to the highest prevalence with a difference of only 5 to 10 percentage points within each health condition, indicating the differences between health outcomes within the city and its census tracts.

Finally, the leaflet map of the prevalence of obesity within Missoula depicts each of the city’s census tracts as a circle whose area is related to the prevalence of obesity within that census tract. Additionally, clicking on any of the census tracts on the map reveals information regarding the FIPS code of that tract, the prevalence of obesity within that census tract, and the population that lives within that census tract. Thus, both the boxplot and the leaflet map illustrate the differences within the health of the census tracts within the relatively small city of Missoula of around 67,000 people.