7.4 Mapping

map@bbox
##         min       max
## x -84.82030 -80.51820
## y  38.40342  42.32713
map@data[1:2,]
##   STATEFP COUNTYFP COUNTYNS CNTYIDFP     NAME        NAMELSAD LSAD CLASSFP
## 0      39      011     <NA>    39011 Auglaize Auglaize County   06      H1
## 1      39      033     <NA>    39033 Crawford Crawford County   06      H1
##   MTFCC UR FUNCSTAT
## 0 G4020  M        A
## 1 G4020  M        A
map <- merge(map, dw, by.x = "NAME", by.y = "county")
map_sf <- st_as_sf(map)
map_sf <- gather(map_sf, year, SIR, paste0("SIR_", 1968:1988))
map_sf$year <- as.integer(substring(map_sf$year, 5, 8))
ggplot(map_sf) + 
  geom_sf(aes(fill = SIR)) +
  facet_wrap(~year, dir = "h", ncol = 7) +
  ggtitle("SIR") + theme_bw() +
  theme(
    axis.text.x = element_blank(),
    axis.text.y = element_blank(),
    axis.ticks = element_blank()
  ) +
  scale_fill_gradient2(
    midpoint = 1, low = "blue", mid = "white", high = "red"
  )

7.4.1 Time plots of SIRs

g <- ggplot(d, 
            aes(x = year, y = SIR, 
                   group = county, 
                   color = county)) +
  geom_line() + 
  geom_point(size = 2) + 
  theme_bw()+
  theme(legend.position = "none")

library(gghighlight)
g + gghighlight(county == "Lorain")

library(plotly)
ggplotly(g)