Introduction:

The CDC’s “PLACES: Local Data for Better Health” provides access to detailed local health data. It helps users explore health indicators by county, city, and census areas to improve public health efforts. The platform offers interactive maps, data tools, and resources for understanding local health measures based on CDC and U.S. Census data. For more details, visit the PLACES website.

This dataset is adapted from 500 Cities: Local Data for Better Health, 2017 release.

Project Prompt:

For this project, you will work with a cleaned dataset and conduct an analysis using GIS techniques.

  1. Start by filtering the dataset further to create a subset containing no more than 900 observations. Choose a specific subset based on a meaningful criterion related to your analysis.

  2. Create a plot that visualizes an aspect of your subsetted dataset. This could be a histogram, scatter plot, or line chart, depending on the nature of your data.

  3. Generate a basic GIS map that represents the geographic distribution of your subsetted data points. Ensure that the map clearly conveys relevant spatial patterns.

  4. Refine your GIS map by adding interactive elements, such as a tooltip that displays information when users click on a data point.

  5. Write a paragraph summarizing your visualizations. Explain what your plot and map reveal about your subsetted dataset. Discuss any trends, patterns, or insights gained from your analysis.

This project will help you practice data filtering, visualization, and GIS mapping techniques, reinforcing concepts from the Japan earthquakes tutorial.

Let’s start:

Load the libraries and set the working directory

library(tidyverse)
library(tidyr)

setwd("~/Downloads/Spring Semester 2025/DATA 110/Week 8/Project 2")

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

Cleaning the data set:

1. The GeoLocation variable has (lat, long) format. We need to split GeoLocation (lat, long) into two columns: lat and long.

To do so, we will remove the parentheses from a column, then split it into separate latitude and longitude columns.

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>

str_replace_all(GeoLocation, "[()]", "") removes any parentheses from the GeoLocation column.

separate(GeoLocation, into = c("lat", "long"), sep = ",", convert = TRUE)

The separate() function splits the GeoLocation column into two new columns:

“lat” (latitude) “long” (longitude)

sep = "," specifies that the values are separated by a comma.

convert = TRUE automatically converts the new columns into appropriate data types (numeric in this case).

2. 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")
dim(md)
## [1] 804  18

Your Work

  1. MD has 804 observations. For this project, start by filtering the dataset further to create a subset containing no more than 900 observations. Choose a specific subset based on a meaningful criterion related to your analysis.
sc <- prevention |>
  filter(StateAbbr == "SC", Short_Question_Text == "Taking BP Medication")
dim(sc)
## [1] 179  18
head(sc)
## # A tibble: 6 × 18
##    Year StateAbbr StateDesc   CityName GeographicLevel Category UniqueID Measure
##   <dbl> <chr>     <chr>       <chr>    <chr>           <chr>    <chr>    <chr>  
## 1  2017 SC        South Caro… North C… Census Tract    Prevent… 4550875… Taking…
## 2  2017 SC        South Caro… Columbia Census Tract    Prevent… 4516000… Taking…
## 3  2017 SC        South Caro… Columbia Census Tract    Prevent… 4516000… Taking…
## 4  2017 SC        South Caro… North C… Census Tract    Prevent… 4550875… Taking…
## 5  2017 SC        South Caro… Rock Hi… Census Tract    Prevent… 4561405… Taking…
## 6  2017 SC        South Caro… Charles… Census Tract    Prevent… 4513330… 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>
  1. Create a plot that visualizes an aspect of your subsetted dataset. This could be a histogram, scatter plot, or line chart, depending on the nature of your data.
library(ggplot2)

ggplot(sc, aes(x = Data_Value)) +
  geom_histogram(fill = "#6ab18d", color = "white", bins = 20) +
  labs(
    title = "BP Medication Usage in South Carolina",
    x = "Percentage of adults taking BP meds (%)",
    y = "Number of Census Tracts") +
  scale_x_continuous(breaks = seq(20, 90, by = 10)) +
  theme_minimal()
## Warning: Removed 7 rows containing non-finite outside the scale range
## (`stat_bin()`).

  1. Generate a basic GIS map that represents the geographic distribution of your subsetted data points. Ensure that the map clearly conveys relevant spatial patterns.
library(leaflet)

sc_lat <- 33.8361
sc_lon <- -81.1637

leaflet() |>
  setView(lng = sc_lon, lat = sc_lat, zoom = 7) |>
  addProviderTiles("Esri.NatGeoWorldMap") |>
  addCircles(
    data = sc,
    lng = ~long,
    lat = ~lat,
    radius =  ~Data_Value * 25,
    fillColor = "tomato",
    fillOpacity = 0.5,
    color = "white", 
    weight = 1.5
  )
  1. Refine your GIS map by adding interactive elements, such as a tooltip that displays information when users click on a data point.
popup<- paste0(
      "<b>City: </b>", sc$CityName, "<br>",
      "<b>BP Medication Usage (%): </b>", sc$Data_Value, "<br>",
      "<b>Population: </b>", sc$PopulationCount, "<br>"
    )
leaflet() |>
  setView(lng = sc_lon, lat = sc_lat, zoom = 7) |>
  addProviderTiles("Esri.NatGeoWorldMap") |>
  addCircles(
    data = sc,
    lng = ~long,
    lat = ~lat,
    radius =  ~Data_Value * 25,
    fillColor = "red",
    fillOpacity = 0.5,
    color = "white", 
    weight = 1.5,
    popup = popup
  )
  1. Write a paragraph summarizing your visualizations. Explain what your plot and map reveal about your subsetted dataset. Discuss any trends, patterns, or insights gained from your analysis.

    The histogram shows the distribution of blood pressure medication usage among adults across census tracts in South Carolina. Most areas have between 60% and 85% of adults taking Blood Pressure medication. However, a few areas report using less, which may suggest, for example, possible gaps in treatment access. The GIS map also support this by showing strong geographic clustering around Columbia and North Charleston. These clusters represent areas where both population and data availability are high. In contrast, some other points have a fewer data points, suggesting lower population density. The size of each circle shows the percentage of adults taking blood pressure medication, while the interactive popups allow individuals to see more details, like the city name and percentage. The map and graph together make it easier to understand where people are getting care and how it can vary by location.