library(tidyverse)
library(tidyr)
library(leaflet)
setwd("C:/Users/dylan/OneDrive/Documents/Data 110 Summer")
cities500 <- read_csv("500CitiesLocalHealthIndicators.cdc.csv")
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>
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>
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"
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>
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>
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"
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"
The new data set “Prevention” is a manageable data set now.
Filter chunk here
subset <- prevention %>%
filter(StateAbbr == "NY")
head(subset)
## # A tibble: 6 × 18
## Year StateAbbr StateDesc CityName GeographicLevel Category UniqueID Measure
## <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 2017 NY New York Buffalo Census Tract Prevent… 3611000… "Chole…
## 2 2017 NY New York Rochester Census Tract Prevent… 3663000… "Curre…
## 3 2017 NY New York Rochester Census Tract Prevent… 3663000… "Visit…
## 4 2017 NY New York Rochester Census Tract Prevent… 3663000… "Chole…
## 5 2017 NY New York Schenecta… Census Tract Prevent… 3665508… "Takin…
## 6 2017 NY New York New York Census Tract Prevent… 3651000… "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>
First plot chunk here
ggplot(subset, aes(x = Data_Value)) +
geom_histogram(binwidth = 1, fill = "blue", color = "black") +
labs(title = "Distribution of Current Lack of Health Insurance (New York 2017)",
x = "Crude Prevalence",
y = "Frequency")
## Warning: Removed 111 rows containing non-finite outside the scale range
## (`stat_bin()`).
First map chunk here
map <- leaflet(subset) %>%
addProviderTiles(providers$Esri.WorldStreetMap) %>%
addCircles(lng = ~long, lat = ~lat, radius = 5, color = "blue",
popup = ~paste("<b>City:</b>", CityName, "<br>",
"<b>Crude Prevalence:</b>", Data_Value, "%"))
map
Refined map chunk here
map <- leaflet(subset) %>%
addProviderTiles(providers$Esri.WorldStreetMap) %>%
addCircleMarkers(
lng = ~long, lat = ~lat, radius = 5, color = "blue",
popup = ~paste("<b>City:</b>", CityName, "<br>",
"<b>Crude Prevalence:</b>", Data_Value, "%"),
label = ~paste("City: ", CityName, "<br>",
"Crude Prevalence: ", Data_Value, "%"),
labelOptions = labelOptions(noHide = FALSE, direction = 'auto'))
map
The produced plots and maps shed light on the availability of health insurance in different New York (State) cities (Buffalo, Rochester, Albany, New York City) in 2017. The distribution of the crude prevalence of adults between the ages of 18 and 64 who do not currently have health insurance is displayed in a histogram graphic. This data is visualized spatially in an interactive map that shows the prevalence rate of each city and provides tool hints for more in-depth information. By highlighting regions with greater numbers of uninsured people, this research may assist direct focused actions to increase access to healthcare.