library(tidyverse)
library(tidyr)
library(leaflet)
setwd("/Users/kidusteffera/Desktop/DATA110/week 10")
cities500 <- read_csv("500CitiesLocalHealthIndicators.cdc (1).csv")
data(cities500)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) |>
mutate(lat = as.numeric(lat),
long = as.numeric(long))
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") |>
filter(Year == 2017) |>
filter(StateAbbr == "MT") |>
filter(CityName == "Missoula") |>
filter(Category == "Health Outcomes")
head(latlong_clean)# A tibble: 6 × 25
Year StateAbbr StateDesc CityName GeographicLevel DataSource Category
<dbl> <chr> <chr> <chr> <chr> <chr> <chr>
1 2017 MT Montana Missoula City BRFSS Health Outcomes
2 2017 MT Montana Missoula Census Tract BRFSS Health Outcomes
3 2017 MT Montana Missoula Census Tract BRFSS Health Outcomes
4 2017 MT Montana Missoula Census Tract BRFSS Health Outcomes
5 2017 MT Montana Missoula Census Tract BRFSS Health Outcomes
6 2017 MT Montana Missoula Census Tract BRFSS Health Outcomes
# ℹ 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
latlong_clean2 <- latlong_clean |>
select(-DataSource, -Data_Value_Unit, -DataValueTypeID,
-Low_Confidence_Limit, -High_Confidence_Limit,
-Data_Value_Footnote_Symbol, -Data_Value_Footnote)
head(latlong_clean2)# A tibble: 6 × 18
Year StateAbbr StateDesc CityName GeographicLevel Category UniqueID Measure
<dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 2017 MT Montana Missoula City Health Ou… 3050200 Chroni…
2 2017 MT Montana Missoula Census Tract Health Ou… 3050200… Stroke…
3 2017 MT Montana Missoula Census Tract Health Ou… 3050200… Arthri…
4 2017 MT Montana Missoula Census Tract Health Ou… 3050200… Physic…
5 2017 MT Montana Missoula Census Tract Health Ou… 3050200… High c…
6 2017 MT Montana Missoula Census Tract Health Ou… 3050200… Corona…
# ℹ 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 “latlong_clean2” is a manageable dataset now.
For your assignment, work with a cleaned dataset where you perform your own cleaning and filtering.
1. Once you run the above code and filter this complicated dataset, perform your own investigation by filtering this dataset however you choose so that you have a subset with no more than 900 observations through some inclusion/exclusion criteria.
Filter chunk here (you may need multiple chunks)
missoula_tracts <- latlong_clean2 |>
filter(GeographicLevel == "Census Tract") |>
filter(Short_Question_Text %in% c("Obesity", "Diabetes",
"High Blood Pressure",
"COPD",
"Coronary Heart Disease")) |>
filter(!is.na(lat), !is.na(long), !is.na(Data_Value))
nrow(missoula_tracts)[1] 64
head(missoula_tracts)# A tibble: 6 × 18
Year StateAbbr StateDesc CityName GeographicLevel Category UniqueID Measure
<dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 2017 MT Montana Missoula Census Tract Health Ou… 3050200… Corona…
2 2017 MT Montana Missoula Census Tract Health Ou… 3050200… High b…
3 2017 MT Montana Missoula Census Tract Health Ou… 3050200… Diagno…
4 2017 MT Montana Missoula Census Tract Health Ou… 3050200… High b…
5 2017 MT Montana Missoula Census Tract Health Ou… 3050200… Corona…
6 2017 MT Montana Missoula Census Tract Health Ou… 3050200… High b…
# ℹ 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>
missoula_tracts |>
count(Short_Question_Text)# A tibble: 4 × 2
Short_Question_Text n
<chr> <int>
1 COPD 16
2 Coronary Heart Disease 16
3 Diabetes 16
4 High Blood Pressure 16
2. Based on the GIS tutorial (Japan earthquakes), create one plot about something in your subsetted dataset.
First plot chunk here
ggplot(missoula_tracts,
aes(x = reorder(Short_Question_Text, Data_Value, median),
y = Data_Value,
fill = Short_Question_Text)) +
geom_boxplot(alpha = 0.8, show.legend = FALSE) +
geom_jitter(width = 0.15, alpha = 0.4, size = 1.2) +
coord_flip() +
labs(title = "Chronic Health Outcomes Across Missoula Census Tracts (2017)",
subtitle = "Crude prevalence (%), one point per census tract",
x = NULL,
y = "Crude prevalence (%)",
caption = "Source: CDC 500 Cities Local Health Indicators") +
theme_minimal(base_size = 12)3. Now create a map of your subsetted dataset.
First map chunk here
missoula_obesity <- missoula_tracts |>
filter(Short_Question_Text == "Obesity")
pal <- colorNumeric(palette = "YlOrRd", domain = missoula_obesity$Data_Value)
leaflet(missoula_obesity) |>
addTiles() |>
addCircleMarkers(
lng = ~long,
lat = ~lat,
radius = ~Data_Value / 3,
color = ~pal(Data_Value),
fillOpacity = 0.7,
stroke = FALSE
) |>
addLegend("bottomright", pal = pal, values = ~Data_Value,
title = "Obesity (%)", opacity = 1)Warning in min(x): no non-missing arguments to min; returning Inf
Warning in max(x): no non-missing arguments to max; returning -Inf
4. Refine your map to include a mouse-click tooltip
Refined map chunk here
leaflet(missoula_tracts) |>
addProviderTiles(providers$CartoDB.Positron) |>
addCircleMarkers(
lng = ~long,
lat = ~lat,
radius = ~Data_Value / 3,
color = ~pal(Data_Value),
fillOpacity = 0.75,
stroke = TRUE,
weight = 1,
popup = ~paste0(
"<b>Census Tract:</b> ", TractFIPS, "<br/>",
"<b>Obesity (crude prevalence):</b> ", Data_Value, "%<br/>",
"<b>Population:</b> ", PopulationCount
),
label = ~paste0("Obesity: ", Data_Value, "%")
) |>
addLegend("topright", pal = pal, values = ~Data_Value,
title = "Obesity (%)", opacity = 1) |>
setView(lng = -114.01, lat = 46.87, zoom = 12)5. Write a paragraph
The analysis that is presented in this report was performed with regard to the city of Missoula, Montana, using the CDC 500 Cities Local Health Indicators data for 2017 at the census-tract level. After filtering the data for only the census tracts that are located within the city limits of Missoula, only the crude prevalence data for each of the five chronic health conditions, the remaining data is still well below the 900 observation limit of the dataset, but is still plentiful in its variations of the factors that relate to the health of the individuals that live within Missoula.
Within the boxplot that represents the prevalence of each of the five chronic conditions within Missoula, the high blood pressure and obesity rates are the most prevalent within the city. Rates of high blood pressure and obesity fall within the 20s and 30s in percentage rates within the census tracts that comprise Missoula. In contrast, conditions like coronary heart disease and COPD are represented by much lower prevalence rates within the population of Missoula, with rates represented in the single digits. Furthermore, the percentage rates of each condition within each of the census tracts within Missoula ranges from the lowest rate to the highest rate for that health condition by only 5 to 10 percentage points.
Finally, within the leaflet map of the obesity rates within Missoula, each of the census tracts within the city are represented as a circle whose area reflects the prevalence of obesity within that census tract. Additionally, if any of the census tracts within the city of Missoula are clicked upon with a computer mouse, the data that appears on the screen reveals information regarding the FIPS code of that census tract, the prevalence of obesity within the census tract, and the population that lives within that census tract. Thus, both the boxplot and the leaflet map allow for the interpretation of the differences in the health among the census tracts within the small city of Missoula, which contains around 67,000 individuals that live within its census tracts.