Healthy Cities GIS Assignment

Author

Allenteena Bernard

Load the libraries and set the working directory

getwd()
[1] "C:/Users/cbash/OneDrive/Desktop/DATA 110"
library(tidyverse)
library(tidyr)
setwd("C:/Users/cbash/OneDrive/Desktop/DATA 110")
cities500 <- read_csv("500CitiesLocalHealthIndicators.cdc.csv")

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(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")
head(md)
# A tibble: 6 × 18
   Year StateAbbr StateDesc CityName  GeographicLevel Category  UniqueID Measure
  <dbl> <chr>     <chr>     <chr>     <chr>           <chr>     <chr>    <chr>  
1  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Chole…
2  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Visit…
3  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Visit…
4  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Curre…
5  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Curre…
6  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Visit…
# ℹ 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 “Prevention” is a manageable dataset now.

For your assignment, work with the cleaned “Prevention” dataset

1. Once you run the above code, filter this dataset one more time for any particular subset.

Filter chunk here

unique(latlong_clean$StateAbbr)
 [1] "AL" "CA" "FL" "CT" "IL" "MN" "NY" "PA" "NC" "OH" "OK" "OR" "TX" "RI" "SC"
[16] "SD" "TN" "UT" "VA" "WA" "AK" "WI" "AZ" "AR" "CO" "DE" "NV" "DC" "GA" "ID"
[31] "HI" "MA" "MI" "IN" "KS" "KY" "IA" "LA" "MD" "ME" "NH" "NJ" "NM" "MO" "MS"
[46] "NE" "MT" "ND" "WV" "VT" "WY"
filtered_prevention <- prevention |>
  filter(StateAbbr == "MD") |>
  filter(Measure == "Current lack of health insurance among adults aged 18\x9664 Years")
head(filtered_prevention)
# A tibble: 6 × 18
   Year StateAbbr StateDesc CityName  GeographicLevel Category  UniqueID Measure
  <dbl> <chr>     <chr>     <chr>     <chr>           <chr>     <chr>    <chr>  
1  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Curre…
2  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Curre…
3  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Curre…
4  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Curre…
5  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Curre…
6  2017 MD        Maryland  Baltimore Census Tract    Preventi… 2404000… "Curre…
# ℹ 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>

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

First plot chunk here

library(ggplot2)

ggplot(filtered_prevention, aes(x = long, y = lat, size = Data_Value, color = Data_Value)) +
  geom_point(alpha = 0.9) +
  scale_size_continuous(range = c(3, 5)) +
  scale_color_gradient(low = "hotpink", high = "black") +
  labs(title = "Lack of Health Insurance in Maryland (2017)",
       x = "Longitude",
       y = "Latitude",
       size = "Crude Prevalence",
       color = "Crude Prevalence") +
  theme_minimal()
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_point()`).

3. Now create a map of your subsetted dataset.

First map chunk here

library(leaflet)
Warning: package 'leaflet' was built under R version 4.4.1
library(maps)
Warning: package 'maps' was built under R version 4.4.1

Attaching package: 'maps'
The following object is masked from 'package:purrr':

    map
# Set MD longtitude and latitude
Maryland_lon <- -76.641273
Maryland_lat <- 39.0458
leaflet() |>
  setView(lng = Maryland_lon, lat = Maryland_lat, zoom = 9) |>
  addProviderTiles("Esri.WorldStreetMap") |>
  addCircles(
    data = filtered_prevention,
    radius = (filtered_prevention$PopulationCount)/10
  )
Assuming "long" and "lat" are longitude and latitude, respectively

4. Refine your map to include a mousover tooltip

popupquake <- paste0(
  "<b>Year: </b>", iconv(filtered_prevention$Year, to = "UTF-8"), "<br>",
  "<b>Geographic Level: </b>", iconv(filtered_prevention$GeographicLevel, to = "UTF-8"), "<br>",
  "<b>Population Count: </b>", iconv(filtered_prevention$PopulationCount, to = "UTF-8"), "<br>",
  "<b>Lack of Insurance Rate: </b>", iconv(filtered_prevention$Data_Value, to = "UTF-8"), "<br>",
  "<b>Measure: </b>", iconv(filtered_prevention$Measure, to = "UTF-8"), "<br>")

# Create the leaflet map
leaflet() |>
  setView(lng = Maryland_lon, lat = Maryland_lat, zoom = 10) |>
  addProviderTiles("Esri.WorldStreetMap") |>
  addCircles(data = filtered_prevention,
             radius = filtered_prevention$PopulationCount / 10,
             color = "#14010d",
             fillColor = "#f2079c",
             fillOpacity = 0.25,
             popup = popupquake)
Assuming "long" and "lat" are longitude and latitude, respectively

5. Write a paragraph

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

In the first plot, scatter plot to visualize the distribution of the lack of health insurance among adults aged 18-64 years across different cities in Maryland for the year 2017. Each point on the scatter plot represents a city, with the size and color of the points indicating the crude prevalence of uninsured adults. Larger and more red-colored points indicate a higher prevalence, while smaller and pinker points indicate a lower prevalence. This plot effectively highlights the variation in health insurance coverage across different locations within the state.

In the second plot, we created a map of Maryland using the leaflet package. The map provides a geographical context, showing the boundaries of Maryland. Overlaid on the map are points representing the lactions within Baltimore county, with the size and color of these points corresponding to the crude prevalence of the lack of health insurance. This visual representation allows for an intuitive understanding of how health insurance coverage varies geographically across the state, pinpointing areas with higher or lower rates of uninsured adults. The combination of the map and the data points offers a clear and detailed view of health insurance disparities within Maryland, particularly in Baltimore area.