library(leaflet)
library(sf)
library(tidyverse)
library(knitr)
library(plotly)
setwd("/Users/nnokigbo/Downloads")
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")
md
## # A tibble: 804 × 18
## Year StateAbbr StateDesc CityName GeographicLevel Category UniqueID Measure
## <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 2017 MD Maryland Baltimore Census Tract Prevent… 2404000… "Chole…
## 2 2017 MD Maryland Baltimore Census Tract Prevent… 2404000… "Visit…
## 3 2017 MD Maryland Baltimore Census Tract Prevent… 2404000… "Visit…
## 4 2017 MD Maryland Baltimore Census Tract Prevent… 2404000… "Curre…
## 5 2017 MD Maryland Baltimore Census Tract Prevent… 2404000… "Curre…
## 6 2017 MD Maryland Baltimore Census Tract Prevent… 2404000… "Visit…
## 7 2017 MD Maryland Baltimore Census Tract Prevent… 2404000… "Curre…
## 8 2017 MD Maryland Baltimore Census Tract Prevent… 2404000… "Takin…
## 9 2017 MD Maryland Baltimore Census Tract Prevent… 2404000… "Curre…
## 10 2017 MD Maryland Baltimore Census Tract Prevent… 2404000… "Chole…
## # ℹ 794 more rows
## # ℹ 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.
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"
fl <- prevention |>
filter(StateAbbr == "FL" & GeographicLevel == "City")
head(fl)
## # A tibble: 6 × 18
## Year StateAbbr StateDesc CityName GeographicLevel Category UniqueID Measure
## <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 2017 FL Florida Palm Coast City Prevent… 1254200 "Curre…
## 2 2017 FL Florida Tampa City Prevent… 1271000 "Chole…
## 3 2017 FL Florida Coral Spr… City Prevent… 1214400 "Curre…
## 4 2017 FL Florida Deerfield… City Prevent… 1216725 "Visit…
## 5 2017 FL Florida Deltona City Prevent… 1217200 "Curre…
## 6 2017 FL Florida Hollywood City Prevent… 1232000 "Takin…
## # ℹ 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
plot1 <- fl |>
ggplot(aes(x = Data_Value, y = PopulationCount, color = MeasureId)) +
geom_point()
plot1
Outliers past 40,000
plot2 <- fl |>
filter(PopulationCount < 400000) |>
ggplot(aes(x = PopulationCount, y = Data_Value, color = MeasureId)) +
geom_point() +
labs(
x = "Data Value",
y = "Population",
title = "HealthCare Quality Based on Population and Measure",
caption = "Source:"
)
#ggplotly(plot2)
plot2
First map chunk here
flpopup <- paste0(
"<b>Magnitude: </b>", fl$Data_Value, "<br>",
"<strong>Place: </strong>", fl$StateAbbr, "<br>")
leaflet() |>
setView(lng = -80.25883, lat = 26.09623, zoom =6) |>
addProviderTiles("Esri.WorldStreetMap") |>
addCircles(
data = fl,
radius = fl$Data_Value,
color = "#14010d",
fillColor = "#f2079c",
fillOpacity = 0.35)
## Assuming "long" and "lat" are longitude and latitude, respectively
Refined map chunk here
leaflet() |>
setView(lng = -80.25883, lat = 26.09623, zoom =6) |>
addProviderTiles("Esri.WorldStreetMap") |>
addCircles(
data = fl,
radius = fl$Data_Value,
color = "#14010d",
fillColor = "#f2079c",
fillOpacity = 0.35,
popup = flpopup)
## Assuming "long" and "lat" are longitude and latitude, respectively
In a paragraph, describe the plots you created and what they show.
I created plots that show how health care quality is spread throughout Florida cities. At first glance map shows how healthcare quality is generally better around larger cities such as Miami and Tampa. The smaller big cities such as Jacksonville and Tallahasse seem to experience worse healthcare. The circles indicate Data values.