Healthy Cities GIS Assignment

Author

Your Name

Load the libraries and set the working directory

library(tidyverse)
library(tidyr)
setwd("/Users/ashleyramirez/Desktop/data110")
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.

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>
tx <- prevention |>
  filter(StateAbbr=="TX")
head(tx)
# A tibble: 6 × 18
   Year StateAbbr StateDesc CityName GeographicLevel Category   UniqueID Measure
  <dbl> <chr>     <chr>     <chr>    <chr>           <chr>      <chr>    <chr>  
1  2017 TX        Texas     Houston  Census Tract    Prevention 4835000… "Chole…
2  2017 TX        Texas     Houston  Census Tract    Prevention 4835000… "Chole…
3  2017 TX        Texas     Irving   Census Tract    Prevention 4837000… "Chole…
4  2017 TX        Texas     Abilene  Census Tract    Prevention 4801000… "Visit…
5  2017 TX        Texas     Austin   Census Tract    Prevention 4805000… "Curre…
6  2017 TX        Texas     Austin   Census Tract    Prevention 4805000… "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>
unique(tx$CityName)
 [1] "Houston"         "Irving"          "Abilene"         "Austin"         
 [5] "Beaumont"        "Brownsville"     "Carrollton"      "Dallas"         
 [9] "Denton"          "El Paso"         "Fort Worth"      "Garland"        
[13] "Grand Prairie"   "Tyler"           "Laredo"          "Lewisville"     
[17] "Longview"        "Lubbock"         "McKinney"        "Odessa"         
[21] "San Antonio"     "Arlington"       "Amarillo"        "Allen"          
[25] "Missouri City"   "Mesquite"        "Bryan"           "Corpus Christi" 
[29] "College Station" "Baytown"         "Midland"         "McAllen"        
[33] "Killeen"         "Edinburg"        "Frisco"          "Pasadena"       
[37] "Mission"         "Pearland"        "League City"     "Plano"          
[41] "Richardson"      "Sugar Land"      "Wichita Falls"   "Waco"           
[45] "Pharr"           "San Angelo"      "Round Rock"     

The new dataset “Prevention” is a manageable dataset now.

For your assignment, work with a cleaned dataset.

-Ashley Ramirez

1. Once you run the above code, filter this dataset one more time for any particular subset with no more than 900 observations.

Filter chunk here

texas_data <- tx  %>%
  filter(StateAbbr == "TX",GeographicLevel == "Census Tract", PopulationCount < 2000 )
Bp_medication <- texas_data %>%
  filter(MeasureId == "BPMED")

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

First plot chunk here

ggplot(Bp_medication, aes(x = CityName, y = PopulationCount)) +
  geom_bar(stat = "identity", fill = "red", color = "black", size = 0.3) +  
  theme_minimal() +
  labs(
    title = "Population Taking Blood Pressure Medication by City in Texas",
    x = "City",
    y = "Population Count",
    caption = "Data source: 500CitiesLocalHealthIndicators.cdc.csv"  
  ) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1))
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.

3. Now create a map of your subsetted dataset.

First map chunk here

#Load leaflet
library(leaflet)
# Create the map 
texas_map <- leaflet(Bp_medication) |>
  setView(lng = -99.9018, lat = 31.9686, zoom = 6) |>
  addProviderTiles("Esri.WorldStreetMap") |>
  addCircles(
    data = Bp_medication,  
    lat = ~lat,  
    lng = ~long,  
    radius = 8,  
    color = "purple",
    fillOpacity = 0.6
  )

# Display the map
texas_map

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

Refined map chunk here

library(leaflet)
map <- leaflet(Bp_medication) %>%
  addTiles() %>%  
  addCircleMarkers(~long, ~lat, 
                   radius = 8, 
                   color = "purple",
                   fillOpacity = 0.2, 
                   popup = ~paste(
                     "City: ", CityName, "<br>", 
                     "City FIPS: ", CityFIPS, "<br>", 
                     "Population: ", PopulationCount, "<br>", 
                     "Category: ", Category, "<br>",
                     "Year: ", Year, "<br>",  
                     "Measure: ", Measure, "<br>", 
                     "Data Value: ", Data_Value))  
map

5. Write a paragraph

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

My work is based around census tracked geographical level of the population in Texas that are 18 or older that take blood pressure medication in order to prevent it. With the previous context in mind the first plot I created was to show how many people across the cities of Texas take blood pressure medication to prevent blood pressure in doing so the results were that Houston have the most people taking bloop pressure medication, followed by Dallas and San Antonio. In that same concept with the previous plot, i wanted to create a map that showed the density in the population of each city in the map of peopel taking the medication, plus extra details the dataset provided to give extra context of the many reasons they might’ve taken it or extra information of their geographical locations. My final thoughts are that the most populated cities consume more medication due to having high population.