Tracking Data Science & Practice Journal Club
Caitlin Kennedy & Emily Prezzato
1/17/2020
How can Tracking leverage data visualization tools to communicate key messages to drive public health actions?
# workspace
library(tidyverse)
library(tidycensus)
library(viridis)
library(tigris)
library(gganimate)
options(tigris_use_cache = TRUE)
# import
data <- read_csv("~/R/Data/ExtremeHeatProjections_A2_90__Full.csv")
# wrangle
EH <- data %>%
mutate(GEOID = as.character(countyFIPS)) %>%
select(everything(),
-c(stateFIPS, countyFIPS, 'Data Comment'))
EH$GEOID <- ifelse(nchar(EH$GEOID) <5,
paste("0", EH$GEOID, sep=""),
EH$GEOID) # adding padded 0
# load Census data
county_pop <- get_acs(geography = "county",
variables = "B01003_001", # total population variable
year = 2016,
geometry = TRUE, # set geometry to FALSE if you want to load TIGER shapefiles
keep_geo_vars = TRUE,
shift_geo = TRUE) %>%# shifts AK and HI
rename(pop = estimate)
geo <- county_pop %>%
select(GEOID, geometry)
# join extreme heat and census dfs
EH_geo <- inner_join(geo, EH, by = 'GEOID') # join full data set by GEOID
EH30 <- EH_geo %>%
filter(Year == 2030)
s <- ggplot(EH30, aes(fill = Value)) +
geom_sf() +
theme_minimal() +
scale_fill_viridis() +
coord_sf(datum = NA) +
labs(title = "Future projections of extreme heat in the US.
\nYear: 2030",
fill = "Extreme heat days") # legend title
This is cool snapshot… but is extreme heat projected to increase?
USmap <- ggplot() +
geom_sf(EH_geo, mapping = aes(fill = Value),
colour = NA) +
scale_fill_viridis_c() +
scale_color_viridis_c() +
theme_minimal() +
coord_sf(datum = NA) +
labs(title = "Future projections of extreme heat in the US.
\nYear: {closest_state}",
fill = "Extreme heat days") +
transition_states(Year,
transition_length = 1,
state_length = 1) +
ease_aes('linear')
# static map of extreme heat in GA, 2030
GA <- EH_geo %>%
filter(State == "Georgia" & Year == 2030)
g <- ggplot(GA, aes(fill = Value)) +
geom_sf() +
theme_minimal() +
scale_fill_viridis() +
coord_sf(datum = NA) +
labs(title = "Future projections of extreme heat in Georgia.
\nYear: 2030",
caption = "Absolute Threshold: 90 degrees F \nEmissions Scenario: High Emissions (A2)",
fill = "Extreme heat days")
GA <- EH_geo %>%
filter(State == "Georgia")
GAmap <- ggplot(GA, aes(fill = Value),
colour = NA) + # interactive example
geom_sf() +
scale_fill_viridis_c() +
scale_color_viridis_c() +
theme_minimal() +
coord_sf(datum = NA) +
labs(title = "Future projections of extreme heat in Georgia.
\nYear: {closest_state}",
caption = "Absolute Threshold: 90 degrees F
\nEmissions Scenario: High Emissions (A2)",
fill = "Extreme heat days") +
transition_states(Year,
transition_length = 1,
state_length = 1) +
ease_aes('cubic-in-out')
What else can I animate?
# workspace
library(tidyverse)
library(ggplot2)
library(viridis)
library(gganimate)
library(gifski)
library(png)
EH <- read_csv("~/R/Data/ExtremeHeatProjections_A2_90__Full.csv")
# select North GA counties
GA <- EH %>%
filter(State == "Georgia" &
County %in% c("Bartow", "Cherokee",
"Forsyth", "Cobb",
"Fulton", "Gwinnett",
"Dekalb", "Rockdale",
"Clayton", "Douglas") &
!is.na(Value))
# map using transition_state()
g <- ggplot(GA,
aes(x = as.factor(County),
y = Value,
fill = County)) +
geom_col()+
coord_flip()+
theme(legend.position = "none") +
labs(title = "Number of projected extreme heat days in Northern Georgia counties.
\nYear: {next_state}",
caption = "Absolute Threshold: 90 degrees F
\nEmissions Scenario: High Emissions (A2)",
x = "",
y = "Extreme Heat Days") +
transition_states(Year,
transition_length = 1,
state_length = 1) +
ease_aes('linear')+
scale_fill_viridis_d() +
geom_text(aes(y=Value,
label=Value,
hjust=0))