Healthy Cities GIS Assignment

library(tidyverse)
library(tidyr)
library(leaflet)
setwd("~/Downloads/DATA110")
cities500 <- read_csv("500CitiesLocalHealthIndicators.cdc.csv")
data(cities500)
cities500 <- read_csv("500CitiesLocalHealthIndicators.cdc.csv", show_col_types = FALSE)
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>
balt_lon <- -76.609383
balt_lat <- 39.299236
latlong_clean <- latlong |>
  filter(StateAbbr == "MD") |>
  filter(Data_Value_Type == "Crude prevalence") |>
  filter(Year == 2016) |>
  filter(CityName == "Baltimore") |>
  filter(CategoryID == "PREVENT")
head(latlong_clean)
# A tibble: 6 × 25
   Year StateAbbr StateDesc CityName  GeographicLevel DataSource Category  
  <dbl> <chr>     <chr>     <chr>     <chr>           <chr>      <chr>     
1  2016 MD        Maryland  Baltimore Census Tract    BRFSS      Prevention
2  2016 MD        Maryland  Baltimore Census Tract    BRFSS      Prevention
3  2016 MD        Maryland  Baltimore Census Tract    BRFSS      Prevention
4  2016 MD        Maryland  Baltimore Census Tract    BRFSS      Prevention
5  2016 MD        Maryland  Baltimore Census Tract    BRFSS      Prevention
6  2016 MD        Maryland  Baltimore 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>
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 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Papan…
2  2016 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Mammo…
3  2016 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Fecal…
4  2016 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Papan…
5  2016 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Older…
6  2016 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Older…
# ℹ 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>
latlong_clean2 |>
  group_by(Short_Question_Text) |>
  summarise(mean_value = mean(Data_Value, na.rm = TRUE)) |>
  arrange(desc(mean_value)) |>
  ggplot(aes(x = reorder(Short_Question_Text, mean_value), y = mean_value, fill = mean_value)) +
  geom_col() +
  scale_fill_gradient(low = "#FADADD", high = "#E75480") +
  labs(
    title = "Average Crude Prevalence of Preventive Healthcare in Baltimore, MD (2016)",
    x = "Health Measure",
    y = "Average Crude Prevalence in %",
    caption = "Pap Smear Data N/A: Data not available for this state from the 2016 BRFSS"
  ) +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1, size = 5, face = "bold"),
    axis.text.y = element_text(size = 7),
    plot.title = element_text(face = "bold", size = 10, hjust = 0.5),
    legend.position = "right"
  )
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_col()`).

latlong_clean2 <- latlong_clean2 |>
  mutate(
    Measure = iconv(Measure, from = "", to = "UTF-8", sub = "") #https://stat.ethz.ch/R-manual/R-devel/library/base/html/iconv.html?
  )
leaflet(latlong_clean2) |>
  addProviderTiles("OpenStreetMap.Mapnik") |>
  setView(lng = balt_lon, lat = balt_lat, zoom = 11) |>
  addCircleMarkers(
    lng = ~long, lat = ~lat,
    popup = ~paste0("<b>City:</b>", CityName, "<br>",
                    "<b>Measure ID:</b>", Short_Question_Text, "<br>",
                    "<b>Population:</b>", PopulationCount, "<br>",
                    "<b>Info:</b>", Measure, "<br>",
                    "<b>Value:</b>", Data_Value, "%"),
    color = "darkred",
    radius = 5,
    fillOpacity = 0.05
  )

Essay:

The two visualizations I created shows the prevalence of preventive healthcare in Baltimore, Maryland in the year 2016. The first visualization shows the average crude prevalence of the different preventive health measures, which includes core preventative services for older women and men, dental visits, colorectal cancer screening, mammography, and pap smear tests, with each bar showing the mean prevalence of that particular health behavior throughout the city. The pink color gradient represents the changes in the uptake with the darker shades indicating a higher participation rate. This visualization shows how some preventive healthcare like colorectal cancer screenings and mammographies are largely carried out and more common, while core preventative services for both women and men had the fewest engagements. So this visualization can be used to show what preventative healthcare were more common and the most important in Baltimore in 2016. The second visualization is a map that shows the spread of these preventive healthcares in different parts of Baltimore. The red circles represent a data point based on the coordinates of a specific city that are clickable to show the city name, health measure, population, and crude prevalence percentage. This visualization helps identify the local-level differences and patterns in the preventive healthcare prevalence in the city of Baltimore.