Healthy Cities GIS Assignment

Author

Vania Halvonik

Load the libraries and set the working directory

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

1. Once you run the above code and learn how to 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.

Filter chunk here (you may need multiple chunks)

# Using the tutorial to seperate out latitude and longitude. 
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>
# Selecting only crude pervelance prevention data from MD in 2017. Also mutating the phrase "health insurance" to "lack health insurance" from the short question text to make the condition clearer to the viewer in the plot below. 
latlong_clean <- latlong %>%
  filter(StateDesc != "United States") %>%
  filter(Data_Value_Type == "Crude prevalence") %>%
  filter(Year == 2017) %>%
  filter(StateAbbr == "MD") %>%
  filter(Category == "Prevention") %>%
  mutate(Short_Question_Text=case_when(
    Short_Question_Text=="Health Insurance" ~ "Lack Health Insurance",
    TRUE ~ Short_Question_Text
  ))
unique(latlong_clean$Measure)
[1] "Cholesterol screening among adults aged >=18 Years"                                                   
[2] "Visits to doctor for routine checkup within the past Year among adults aged >=18 Years"               
[3] "Current lack of health insurance among adults aged 18\x9664 Years"                                    
[4] "Taking medicine for high blood pressure control among adults aged >=18 Years with high blood pressure"
dim(latlong_clean)
[1] 804  25

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

# Creating a ggplot scatterplot with x= prevelance data, y=latitude, and color=which type of prevelance data. 
ggplot(latlong_clean, aes(x=Data_Value, y=lat, color = Short_Question_Text)) +
  geom_point(alpha = 0.001) +
  scale_color_viridis_d(option="plasma") +
  geom_jitter() +
  labs(title = "Prevalence Across Different Latitudes in MD by Preventative Behavior", 
       x = "Crude Prevalence", 
       y = "Latitude", 
       color = "Preventative Behavior") +
  theme_bw()
Warning: Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).

3. Now create a map of your subsetted dataset.

# Using leaflet to plot my clean dataset over a map. Note that radius=data value leaves out information, since the same location should have multiple data values, but there is only one radius for each location. I will fix the confusion with a tooltip below. 
library(leaflet)
Warning: package 'leaflet' was built under R version 4.6.1
gis_map <- leaflet() %>%
  setView(lng = -76.6, lat = 39.3, zoom =11) %>%
  addProviderTiles("Esri.WorldStreetMap") %>%
  addCircles(
    data = latlong_clean,
    radius = latlong_clean$Data_Value
  )
Assuming "long" and "lat" are longitude and latitude, respectively
gis_map

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

# Creating a wider dataset where each type of prevention data has its own column so that I can display each type of data for a single circle. 
wide_latlong <- latlong_clean %>%
  pivot_wider(id_cols = c(TractFIPS, PopulationCount, lat, long), names_from = Short_Question_Text, values_from = Data_Value)

# Creating the tooltip popup that provides info on all 4 types of prevention data. 
gis_popup <- paste0(
  "<b>Population: </b>", wide_latlong$PopulationCount, "<br>",
  "<b>Lack Health Insurance: </b>", wide_latlong$`Lack Health Insurance`, "<br>",
  "<b>Annual Checkup: </b>", wide_latlong$`Annual Checkup`, "<br>",
  "<b>Cholesterol Screening: </b>", wide_latlong$`Cholesterol Screening`, "<br>",
  "<b>Taking BP Medication: </b>", wide_latlong$`Taking BP Medication`, "<br>",
  "<wide_latlong>TractFIPS: </wide_latong>", wide_latlong$TractFIPS, "<br>"
)

# Adding the popup and removing the radius from my previous map. 
popup_map <- leaflet() %>%
  setView(lng = -76.6, lat = 39.3, zoom =11.25) %>%
  addProviderTiles("Esri.WorldStreetMap") %>%
  addCircles(
    data = wide_latlong,
    popup=gis_popup
  )
Assuming "long" and "lat" are longitude and latitude, respectively
popup_map

5. Write a paragraph

In part 2, I created a scatterplot with crude prevalence data on the x-axis and latitude on the y-axis. This data is only for prevention data from Maryland from 2017 (Baltimore is the only city in MD with data). There were 4 different prevention data measures: “Cholesterol screening among adults aged >=18 Years”, “Visits to doctor for routine checkup within the past Year among adults aged >=18 Years”, “Current lack of health insurance among adults aged 18>= Years”, and “Taking medicine for high blood pressure control among adults aged >=18 Years with high blood pressure”. The scatterplot is colored by prevention data measure. The plot shows slightly higher rates of being uninsured in lower latitudes compared to higher latitudes, and the plot shows slightly lower rates of blood pressure medication, annual checkups, and cholesterol screening in those same lower latitudes. In part 4, I created a map of Baltimore, MD with circles on all TractFIPS geographic areas we have data for (note that part 3 is a cruder version of part 4). Clicking on a circle displays the population, TractFIPS, and prevalence data for each of the 4 prevention measures for that area.