library(tidyverse)
library(tidyr)
library(leaflet)
setwd("E:/data-110")
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(Data_Value_Type == "Crude prevalence")
head(latlong_clean)# 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 Unhealthy Beh…
4 2017 CA California Indio Census Tract BRFSS Health Outcom…
5 2017 CA California Inglewood Census Tract BRFSS Health Outcom…
6 2016 CA California Inglewood City 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 CA California Hawthorne Census Tract Health … 0632548… "Arthr…
2 2017 CA California Hawthorne City Unhealt… 632548 "Curre…
3 2017 CA California Hayward City Unhealt… 633000 "Obesi…
4 2017 CA California Indio Census Tract Health … 0636448… "Arthr…
5 2017 CA California Inglewood Census Tract Health … 0636546… "Diagn…
6 2016 CA California Inglewood City Prevent… 636546 "Mammo…
# ℹ 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
DMV <- prevention |>
filter(StateAbbr %in% c( "MD", "VA", "DC" ) ) |>
filter(MeasureId == "ACCESS2" )
DMV_OBESITY <- prevention |>
filter(StateAbbr %in% c( "MD", "VA", "DC" ) ) |>
filter(MeasureId == "OBESITY" )
DMV_BINGE <- prevention |>
filter(StateAbbr %in% c( "MD", "VA", "DC" ) ) |>
filter(MeasureId == "BINGE" )
head(DMV)# A tibble: 6 × 18
Year StateAbbr StateDesc CityName GeographicLevel Category UniqueID Measure
<dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 2017 DC District o… Washing… Census Tract Prevent… 1150000… "Curre…
2 2017 DC District o… Washing… Census Tract Prevent… 1150000… "Curre…
3 2017 DC District o… Washing… Census Tract Prevent… 1150000… "Curre…
4 2017 DC District o… Washing… Census Tract Prevent… 1150000… "Curre…
5 2017 DC District o… Washing… Census Tract Prevent… 1150000… "Curre…
6 2017 DC District o… Washing… Census Tract Prevent… 1150000… "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
ggplot( DMV, aes(x = StateAbbr, y = Data_Value, color = StateAbbr)) +
geom_boxplot(outlier.colour="black", outlier.shape=16,
outlier.size=2, notch=FALSE) +
geom_jitter(shape=16, position=position_jitter(0.4)) +
scale_color_brewer(palette = "Set1") +
theme_bw() +
labs( title = "Disparities in Health Insurance: DMV", color = "State" ) +
guides(color = guide_legend(override.aes = list(size = 5))) +
ylab( "Lacking Health Insurance (Percent)" ) +
xlab( "State/Peoples w/out Representation" ) +
theme( legend.position = c(0.15,0.8),
plot.title = element_text(hjust = 0.5) )Warning: Removed 3 rows containing non-finite values (`stat_boxplot()`).
Warning: Removed 3 rows containing missing values (`geom_point()`).
3. Now create a map of your subsetted dataset.
First map chunk here
leaflet() |>
setView(lng = -77.039, lat = 38.9, zoom = 11) |>
addProviderTiles(providers$CartoDB.Positron) |>
addCircles(
data = DMV,
radius = DMV$Data_Value*10,
color = "#14010d",
fillColor = "#f2079c",
fillOpacity = 0.25)Assuming "long" and "lat" are longitude and latitude, respectively
4. Refine your map to include a mousover tooltip
Refined map chunk here
palette <- colorNumeric(
palette = c( "red","orange", "skyblue", "purple", "navy" ), # define your color range
domain = DMV$Data_Value # define the data range
)
popupDMV <- paste0(
"<strong>City: </strong>", DMV$CityName, "<br>",
"<b>Year: </b>", DMV$Year, "<br>",
"<b>Population: </b>", DMV$PopulationCount, "<br>",
"<b>Lack HC Access %: </b>", DMV$Data_Value, "<br>",
"<b>Obesity %: </b>", DMV_OBESITY$Data_Value, "<br>",
"<b>Binge Drinking %: </b>", DMV_BINGE$Data_Value, "<br>"
)
leaflet() %>%
setView(lng = -77.039, lat = 38.9, zoom = 11.4) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addCircles(
data = DMV,
radius = ~Data_Value * 10,
color = ~palette(Data_Value),
fillColor = ~palette(Data_Value),
fillOpacity = 0.9,
popup = popupDMV
)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. Plot 1 shows the difference in the lack of insurance coverage in the DMV (although the data seems to be central to certain densely populated areas). It demonstrates that Virginia has a wider range of coverage depending on the location reaching a high above 30%, whereas Maryland reaches ~ 25% at its peak. Plot 2, being a crude version of plot 3, shows the vague disparities in coverage in VA with its bigger circles. Plot 3 demonstrates, through color and size, the outliers and the potential socioeconomic differences in DC. It must be noted that the data set only looked at Baltimore as it pertained to Maryland, so the map is not as fleshed out as i would have preferred. You could almost draw a line along where the red and orange points meet, possibly indicating wealthier areas of DC. I also added Obesity & binge drinking to the popup to allow for further analysis. I will be adding the Maps for those two health outcomes below this. The white background was added for further contrast with the data points. The binge drinking rates are highest in the center of DC (you could probably guess why), and the obesity rates follow similar lines to the healthcare coverage as seen below.
palette <- colorNumeric(
palette = c( "red","orange", "skyblue", "purple", "navy" ), # define your color range
domain = DMV_BINGE$Data_Value # define the data range
)
popupDMV <- paste0(
"<strong>City: </strong>", DMV$CityName, "<br>",
"<b>Year: </b>", DMV$Year, "<br>",
"<b>Population: </b>", DMV$PopulationCount, "<br>",
"<b>Lack HC Access %: </b>", DMV$Data_Value, "<br>",
"<b>Obesity %: </b>", DMV_OBESITY$Data_Value, "<br>",
"<b>Binge Drinking %: </b>", DMV_BINGE$Data_Value, "<br>"
)
leaflet() %>%
setView(lng = -77.039, lat = 38.9, zoom = 11.4) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addCircles(
data = DMV_BINGE,
radius = ~Data_Value * 10,
color = ~palette(Data_Value),
fillColor = ~palette(Data_Value),
fillOpacity = 0.9,
popup = popupDMV
)Assuming "long" and "lat" are longitude and latitude, respectively
palette <- colorNumeric(
palette = c( "red","orange", "skyblue", "purple", "navy" ), # define your color range
domain = DMV_OBESITY$Data_Value # define the data range
)
popupDMV <- paste0(
"<strong>City: </strong>", DMV$CityName, "<br>",
"<b>Year: </b>", DMV$Year, "<br>",
"<b>Population: </b>", DMV$PopulationCount, "<br>",
"<b>Lack HC Access %: </b>", DMV$Data_Value, "<br>",
"<b>Obesity %: </b>", DMV_OBESITY$Data_Value, "<br>",
"<b>Binge Drinking %: </b>", DMV_BINGE$Data_Value, "<br>"
)
leaflet() %>%
setView(lng = -77.039, lat = 38.9, zoom = 11.4) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addCircles(
data = DMV_OBESITY,
radius = ~Data_Value * 10,
color = ~palette(Data_Value),
fillColor = ~palette(Data_Value),
fillOpacity = 0.9,
popup = popupDMV
)Assuming "long" and "lat" are longitude and latitude, respectively