Healthy Cities GIS Assignment

Author

Bertha O

Womens Health in D.C.

Load the libraries and set the working directory

library(tidyverse)
library(tidyr)
setwd("/Users/bettyovalle/Desktop/College/007 – Spring 2026/DATA 110/week 10")
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.

unique(cities500$MeasureId)
 [1] "ARTHRITIS"    "CSMOKING"     "CHD"          "OBESITY"      "CHOLSCREEN"  
 [6] "BINGE"        "COPD"         "DIABETES"     "MAMMOUSE"     "TEETHLOST"   
[11] "CASTHMA"      "ACCESS2"      "KIDNEY"       "STROKE"       "DENTAL"      
[16] "LPA"          "SLEEP"        "BPHIGH"       "CANCER"       "CHECKUP"     
[21] "PAPTEST"      "PHLTH"        "MHLTH"        "COREM"        "HIGHCHOL"    
[26] "BPMED"        "COLON_SCREEN" "COREW"       

Professor, I had to remove the year 2017 because it was filtering out all of my data.

latlong_clean <- latlong |>
  filter(StateDesc != "United States") |>
  filter(Data_Value_Type == "Crude prevalence") |>
  filter(StateAbbr == "DC") |>
  filter(MeasureId %in% c("MAMMOUSE", "PAPTEST"))
head(latlong_clean)
# A tibble: 6 × 25
   Year StateAbbr StateDesc     CityName   GeographicLevel DataSource Category  
  <dbl> <chr>     <chr>         <chr>      <chr>           <chr>      <chr>     
1  2016 DC        District of C Washington Census Tract    BRFSS      Prevention
2  2016 DC        District of C Washington Census Tract    BRFSS      Prevention
3  2016 DC        District of C Washington Census Tract    BRFSS      Prevention
4  2016 DC        District of C Washington Census Tract    BRFSS      Prevention
5  2016 DC        District of C Washington Census Tract    BRFSS      Prevention
6  2016 DC        District of C Washington 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

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  2016 DC        District o… Washing… Census Tract    Prevent… 1150000… "Mammo…
2  2016 DC        District o… Washing… Census Tract    Prevent… 1150000… "Papan…
3  2016 DC        District o… Washing… Census Tract    Prevent… 1150000… "Mammo…
4  2016 DC        District o… Washing… Census Tract    Prevent… 1150000… "Mammo…
5  2016 DC        District o… Washing… Census Tract    Prevent… 1150000… "Papan…
6  2016 DC        District o… Washing… Census Tract    Prevent… 1150000… "Papan…
# ℹ 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)

names(latlong_clean2)
 [1] "Year"                "StateAbbr"           "StateDesc"          
 [4] "CityName"            "GeographicLevel"     "Category"           
 [7] "UniqueID"            "Measure"             "Data_Value_Type"    
[10] "Data_Value"          "PopulationCount"     "lat"                
[13] "long"                "CategoryID"          "MeasureId"          
[16] "CityFIPS"            "TractFIPS"           "Short_Question_Text"

I will focus only on Women’s Health: “MAMMOUSE” - Mammography “PAPTEST” - Papanicolaou Test

unique(latlong_clean2$MeasureId)
[1] "MAMMOUSE" "PAPTEST" 

It was already filtered above, but I am double checking here using trimws() to make sure there are no spaces affecting the results.

WomensHealth <- latlong_clean2 |>
  filter(trimws(MeasureId) %in% c("MAMMOUSE", "PAPTEST"))

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

First plot chunk here

ggplot(WomensHealth, aes(x = MeasureId, y = Data_Value, color = MeasureId)) +
  geom_jitter(alpha = 0.5, width = 0.2) +
  scale_color_manual(values = c(
    "MAMMOUSE" = "plum",
    "PAPTEST"  = "powderblue"
  )) +
  labs(title = "Women’s Health Indicators (2016)",
       x = "Measure Type",
       y = "Data Value",
       color = "Measure") +
  theme_bw()
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).

My plot shows the percentage of women who received Mammography or Papanicolaou Test health services.

papTest <- WomensHealth |>
  filter(MeasureId == "PAPTEST")
ggplot(papTest, aes(x = Data_Value)) +
  geom_density(fill = "powderblue", alpha = 0.5) +
  labs(title = "Distribution of Papanicolaou Test Data Values",
       x = "Estimated percentage of women receiving Papanicolaou Test",
       y = "Frequency", #is density a good word for this professor?
) +
  theme_bw()
Warning: Removed 1 row containing non-finite outside the scale range
(`stat_density()`).

3. Now create a map of your subsetted dataset.

First map chunk here

# leaflet()
library(leaflet)

leaflet() |>
  setView(lng = -77.0369, lat = 38.9072, zoom = 12) |>
  addProviderTiles("CartoDB.Positron")

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

Refined map chunk here

names(WomensHealth)
 [1] "Year"                "StateAbbr"           "StateDesc"          
 [4] "CityName"            "GeographicLevel"     "Category"           
 [7] "UniqueID"            "Measure"             "Data_Value_Type"    
[10] "Data_Value"          "PopulationCount"     "lat"                
[13] "long"                "CategoryID"          "MeasureId"          
[16] "CityFIPS"            "TractFIPS"           "Short_Question_Text"
leaflet(WomensHealth) |>
  setView(lng = -77.0369, lat = 38.9072, zoom = 11) |>
  addProviderTiles("CartoDB.Positron") |>
  addCircles(
    lng = ~long,
    lat = ~lat,
    radius = ~Data_Value * 4,
    color = "paleturquoise",
    fillColor = "plum",
    fillOpacity = 0.5)
leaflet(WomensHealth) |>
  setView(lng = -77.0369, lat = 38.9072, zoom = 12) |>
  addProviderTiles("CartoDB.Positron") |>
  addCircles(
    lng = ~long,
    lat = ~lat,
    radius = ~Data_Value* 2,
    color = "plum4",
    fillColor = "powderblue",
    fillOpacity = 0.5,
    popup = ~paste0(
      "Measure: ", MeasureId, "<br>",
      "Value: ", Data_Value, "%<br>",
      "Year: ", Year, "<br>",
      "City: ", CityName)
    )

Final Map:

pal <- colorFactor(
  palette = c("plum", "powderblue"),
  domain = WomensHealth$MeasureId)

popup_health <- paste0(
  "<b>Measure: </b>", WomensHealth$MeasureId, "<br>",
  "<b>Value: </b>", WomensHealth$Data_Value, "%<br>",
  "<b>Year: </b>", WomensHealth$Year, "<br>",
  "<b>City: </b>", WomensHealth$CityName, "<br>")
leaflet(WomensHealth) |>
  setView(lng = -77.0369, lat = 38.9072, zoom = 11) |>
  addProviderTiles("CartoDB.Positron") |>
  addCircles(
    lng = ~long,
    lat = ~lat,
    radius = ~Data_Value * 2,
    color = ~pal(MeasureId),
    fillColor = ~pal(MeasureId),
    fillOpacity = 0.5,
    popup = ~popup_health)

5. Summary

The plots show information about women’s health in Washington, D.C., focusing on Mammography (MAMMOUSE) and the Papanicolaou test (PAPTEST). The first plot compares the values of both health measures and shows how they vary. The density plot shows how Papanicolaou test values are distributed, helping to see which values are more common. The map shows the locations of these women’s health indicators in D.C.area (Using lat and long). Overall, the plots help us understand how women’s health data i distributed in Washington, D.C.