library(tidyverse)
library(tidyr)
library(leaflet)
setwd("~/24X Course Work/DATA110")
cities500 <- read_csv("500CitiesLocalHealthIndicators.cdc.csv")Healthy Cities GIS Assignment
Load the libraries and set the working directory
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>
nj <- prevention |>
filter(StateAbbr=="NJ")
head(nj)# A tibble: 6 × 18
Year StateAbbr StateDesc CityName GeographicLevel Category UniqueID Measure
<dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 2017 NJ New Jersey Camden Census Tract Prevent… 3410000… "Curre…
2 2017 NJ New Jersey Clifton Census Tract Prevent… 3413690… "Takin…
3 2017 NJ New Jersey Newark Census Tract Prevent… 3451000… "Curre…
4 2017 NJ New Jersey Jersey C… Census Tract Prevent… 3436000… "Chole…
5 2017 NJ New Jersey Paterson Census Tract Prevent… 3457000… "Chole…
6 2017 NJ New Jersey Union Ci… Census Tract Prevent… 3474630… "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>
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"
njLL <- latlong |>
filter(StateAbbr=="NJ") |>
filter(Category == "Health Outcomes") |>
filter(Year == 2016)
head(njLL)# A tibble: 6 × 25
Year StateAbbr StateDesc CityName GeographicLevel DataSource Category
<dbl> <chr> <chr> <chr> <chr> <chr> <chr>
1 2016 NJ New Jersey Trenton Census Tract BRFSS Health Outc…
2 2016 NJ New Jersey Paterson Census Tract BRFSS Health Outc…
3 2016 NJ New Jersey Jersey City Census Tract BRFSS Health Outc…
4 2016 NJ New Jersey Camden Census Tract BRFSS Health Outc…
5 2016 NJ New Jersey Newark Census Tract BRFSS Health Outc…
6 2016 NJ New Jersey Trenton Census Tract BRFSS Health Outc…
# ℹ 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>
2. Based on the GIS tutorial (Japan earthquakes), create one plot about something in your subsetted dataset.
First plot chunk here
ggplot(njLL, aes(x=CityName, y=Data_Value, fill = CityName)) +
geom_boxplot() +
theme_bw() +
xlab("City in NJ") +
ylab ("Teeth Loss Score") +
labs(title = "Teeth Loss Metrics in various Cities in NJ in 2016",
caption = "Source: USGS")3. Now create a map of your subsetted dataset.
First map chunk here
nj_LONG <- -74.4057
nj_LAT <- 40.40
njPal <- colorNumeric(
palette = "OrRd",
domain = njLL$Data_Value
)
leaflet() |>
setView(lng = nj_LONG, lat = nj_LAT, zoom = 8) |>
addProviderTiles("OpenStreetMap.HOT") |>
addCircles(
data=njLL,
radius= (njLL$Data_Value)^2.25,
color= njPal(njLL$Data_Value),
fillOpacity = 0.33
)Assuming "long" and "lat" are longitude and latitude, respectively
4. Refine your map to include a mouse-click tooltip
Refined map chunk here
njpopup <- paste0(
"<b>City: </b>", njLL$CityName, "<br>",
"<b>Teeth Loss Score: </b>", njLL$Data_Value, "<br>",
"<b>Population: </b>", njLL$PopulationCount, "<br>",
"<b>Data Value Type: </b>", njLL$Data_Value_Type, "<br>"
)
leaflet() |>
setView(lng = nj_LONG, lat = nj_LAT, zoom = 8) |>
addProviderTiles("OpenStreetMap.HOT") |>
addCircles(
data=njLL,
radius= (njLL$Data_Value)^2.25,
color= njPal(njLL$Data_Value),
fillOpacity = 0.33,
popup = njpopup
)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.
For this assignment, I decided to focus on Teeth Loss and how it’s felt differently between various cities in New Jersey (my home state). The first plot directly showcases the differences in Teeth Loss measured, setting each recorded city side by side. Camden, near Philadelphia, seems to have a much higher score than other recorded cities. Some cities with particularly low teeth loss scores are Jersey City, Union City, and Clifton, which can be better explained in the mapped visualization. We could draw a conclusion, if given access to income levels to this cities, that perhaps better access to healthcare with wealth directly impacts how teeth loss affects Adults in these regions. Other statistics, such as drug use in these areas, dentistry access, etc. may also inform why this is.
In our mapped visualizations, it seems like a proximity to NYC has an increase in teeth retention. As previously mentioned, cities like Union City, Jersey City, and Clifton have much lower teeth loss scores. These areas are known for being more affluent than those compared and reside just outside New York City. Given the cost of living in these areas, we can infer that income levels directly impact access to healthcare and dentistry, which can affect whether or not teeth are well maintained or given treatment as needed.