Healthy Cities GIS Assignment

Author

M Madinko

Load the libraries and set the working directory

library(tidyverse)
library(tidyr)

setwd("C:/Users/monik/OneDrive/Desktop/DATA 110")

cities500 <- read_csv("500CitiesLocalHealthIndicators.cdc.csv")

head(cities500)
# A tibble: 6 × 24
   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…
# ℹ 17 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>, GeoLocation <chr>, CategoryID <chr>,
#   MeasureId <chr>, CityFIPS <dbl>, TractFIPS <dbl>, Short_Question_Text <chr>

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(Data_Value_Type == "Crude prevalence") |> 
  filter(Year == 2017) |>   filter(StateAbbr == "CT") |> 
  filter(Category == "Unhealthy Behaviors")
head(latlong_clean)
# A tibble: 6 × 25
   Year StateAbbr StateDesc   CityName   GeographicLevel DataSource Category    
  <dbl> <chr>     <chr>       <chr>      <chr>           <chr>      <chr>       
1  2017 CT        Connecticut Bridgeport Census Tract    BRFSS      Unhealthy B…
2  2017 CT        Connecticut Danbury    City            BRFSS      Unhealthy B…
3  2017 CT        Connecticut Norwalk    Census Tract    BRFSS      Unhealthy B…
4  2017 CT        Connecticut Bridgeport Census Tract    BRFSS      Unhealthy B…
5  2017 CT        Connecticut Hartford   Census Tract    BRFSS      Unhealthy B…
6  2017 CT        Connecticut Waterbury  Census Tract    BRFSS      Unhealthy B…
# ℹ 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 CT        Connecticut Bridgep… Census Tract    Unhealt… 0908000… Obesit…
2  2017 CT        Connecticut Danbury  City            Unhealt… 918430   Obesit…
3  2017 CT        Connecticut Norwalk  Census Tract    Unhealt… 0955990… Obesit…
4  2017 CT        Connecticut Bridgep… Census Tract    Unhealt… 0908000… Curren…
5  2017 CT        Connecticut Hartford Census Tract    Unhealt… 0937000… Obesit…
6  2017 CT        Connecticut Waterbu… Census Tract    Unhealt… 0980000… Obesit…
# ℹ 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)

mycleandata <- latlong |>  
  filter(StateAbbr == "TX") |>  
  filter(Year == 2017) |> 
  filter(Data_Value_Type == "Crude prevalence") |>  
  filter(Measure == "Diagnosed diabetes among adults aged >=18 Years") |>
  filter(GeographicLevel == "Census Tract")|>
  filter(!is.na(Data_Value)) |>  
  filter(CityName %in% c("El Paso", "Austin", "San Antonio", "Fort Worth", "Laredo")) |>  
  select(CityName, PopulationCount, Data_Value, lat, long, Category, Measure) 
head(mycleandata)
# A tibble: 6 × 7
  CityName   PopulationCount Data_Value   lat  long Category        Measure     
  <chr>                <dbl>      <dbl> <dbl> <dbl> <chr>           <chr>       
1 Austin                3712       13.6  30.3 -97.7 Health Outcomes Diagnosed d…
2 Austin                3475        6.8  30.4 -97.8 Health Outcomes Diagnosed d…
3 Fort Worth            2202       14.4  32.7 -97.5 Health Outcomes Diagnosed d…
4 Fort Worth            9155        9    32.6 -97.4 Health Outcomes Diagnosed d…
5 Fort Worth           16579        5.6  32.9 -97.3 Health Outcomes Diagnosed d…
6 Austin                2825        3.5  30.3 -97.8 Health Outcomes Diagnosed d…

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

First plot chunk here

ggplot(mycleandata, aes(x = CityName, y = Data_Value, fill = CityName)) +
  geom_boxplot() +
  scale_fill_manual(values = c(
    "El Paso" = "red",
    "Austin" = "blue",
    "San Antonio" = "green",
    "Fort Worth" = "purple",
    "Laredo" = "orange"
  )) +
  labs(
    title = "Comparison of Diabetes Prevalence Across Texas Cities",
    x = "City",
    y = "Prevalence (%)"
  ) +
  theme_minimal()

3. Now create a map of your subsetted dataset.

First map chunk here

# leaflet()
library(leaflet)
leaflet(mycleandata) |>
  setView(lng = mean(mycleandata$long, na.rm = TRUE),
          lat = mean(mycleandata$lat, na.rm = TRUE),
          zoom = 5) |>
  addProviderTiles("Esri.WorldStreetMap") |>
  addCircles(
    data=mycleandata,
    radius = ~Data_Value * 2500,
    color = "black",
    fillColor = "red",
    fillOpacity = 0.5
  )

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

Refined map chunk here

popupdata <- paste0(
  "<b>City: </b>", mycleandata$CityName, "<br>",
  "<b>Diabetes (%): </b>", mycleandata$Data_Value, "<br>",
  "<b>Category: </b>", mycleandata$Category, "<br>",
  "<b>Measure: </b>", mycleandata$Measure, "<br>"
)

4.a Add popup

# leaflet()
library(leaflet)
leaflet(mycleandata) |>
  setView(lng = mean(mycleandata$long, na.rm = TRUE),
          lat = mean(mycleandata$lat, na.rm = TRUE),
          zoom = 5) |>
  addProviderTiles("Esri.WorldStreetMap") |>
  addCircles(
    data=mycleandata,
    radius = ~Data_Value * 2500,
    color = "black",
    fillColor = "red",
    fillOpacity = 0.5,
    popup = popupdata
  )

5. Write a paragraph

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

I chose to study the state of Texas because my husband was assigned there as part of his military service. He visited several cities, including Laredo and El Paso, which influenced my interest in this region. At first, these cities were part of my personal interest in the study. However, after exploring the data, I also included other major cities such as Austin, Dallas, San Antonio, and Fort Worth in order to have a better representation of urban areas in Texas.In analyzing diabetes prevalence data, I observed differences between cities. Some major cities such as Austin and Dallas appear to have relatively lower levels of diabetes compared to other areas such as Laredo or El Paso. To prepare the analysis, I applied several filters to the dataset. First, I selected only the state of Texas, then restricted the data to the year 2017 to ensure consistency over time. I then kept only records with “crude prevalence” and the measure “diagnosed diabetes among adults aged 18 years and older.” I removed missing values and limited the dataset to the five selected cities. Finally, I retained only the essential variables: CityName, PopulationCount, Data_Value, latitude, and longitude. I created two visualizations. First, a boxplot was used to compare the distribution of diabetes prevalence across the selected cities.It shows how diabetes rates vary within each city.Second, a Leaflet map was created to visualize the geographic distribution of diabetes across these selected cities in Texas. Each point represents a census tract, and the size of the circles reflects the level of diabetes prevalence.

Filter city as a geographical level

mycleandata1 <- latlong |>  
  filter(StateAbbr == "TX") |>  
  filter(Year == 2017) |> 
  filter(Data_Value_Type == "Crude prevalence") |>  
  filter(Measure == "Diagnosed diabetes among adults aged >=18 Years") |>  
  filter(!is.na(Data_Value)) |>  
  filter(GeographicLevel == "City")|>  
  select(CityName, PopulationCount, Data_Value, lat, long, Category, Measure) 
head(mycleandata1)
# A tibble: 6 × 7
  CityName  PopulationCount Data_Value   lat   long Category        Measure     
  <chr>               <dbl>      <dbl> <dbl>  <dbl> <chr>           <chr>       
1 Arlington          365438       10.4  32.7  -97.1 Health Outcomes Diagnosed d…
2 Amarillo           190695       11.6  35.2 -102.  Health Outcomes Diagnosed d…
3 Allen               84246        7.6  33.1  -96.7 Health Outcomes Diagnosed d…
4 Abilene            117063       10.9  32.5  -99.7 Health Outcomes Diagnosed d…
5 Baytown             71802       11.9  29.8  -95.0 Health Outcomes Diagnosed d…
6 Beaumont           118296       13.9  30.1  -94.1 Health Outcomes Diagnosed d…
# leaflet()
library(leaflet)
leaflet(mycleandata1) |>
  setView(lng = mean(mycleandata1$long, na.rm = TRUE),
          lat = mean(mycleandata1$lat, na.rm = TRUE),
          zoom = 5) |>
  addProviderTiles("Esri.WorldStreetMap") |>
  addCircles(
    data=mycleandata1,
    radius = ~Data_Value * 2500,
    color = "black",
    fillColor = "red",
    fillOpacity = 0.6,
    popup = popupdata
  )