Tracking Data Science & Practice Journal Club

DataViz & Storytelling

Caitlin Kennedy & Emily Prezzato
1/17/2020

Purpose of today's presentation

How can Tracking leverage data visualization tools to communicate key messages to drive public health actions?

  • RStudio - ggplot, plotly
  • RMarkdown - flexdashboard
  • RShiny - shinydashboard
  • ArcGIS StoryMaps

Create a static map

# 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")

Create a static map

# 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 

Create a static map

# 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) 

Create a static map

# join extreme heat and census dfs
EH_geo <- inner_join(geo, EH, by = 'GEOID') # join full data set by GEOID

Create a static map

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

Create a static map

plot of chunk unnamed-chunk-6

This is cool snapshot… but is extreme heat projected to increase?

Create an animated map

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')

Create an animated map

plot of chunk unnamed-chunk-8

Create an static map part 2

# 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")

Create a static map part 2

plot of chunk unnamed-chunk-10

Create an animated map part 2

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')

Create an animated map part 2

plot of chunk unnamed-chunk-12

What else can I animate?

Create an animated chart

# workspace
library(tidyverse)
library(ggplot2)
library(viridis)
library(gganimate)
library(gifski)
library(png)

Create an animated chart

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))

Create an animated chart

# 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)) 

Create an animated chart

plot of chunk unnamed-chunk-16