April 14, 2022

Flows to Marion County

The tidycensus package is really neat. There is an example in the vignettes that tracks flows of people by county that I wanted to recreate for Marion County Oregon. It is the vignette on other datasets.

library(tidycensus)
library(tidyverse)
library(tigris)
options(tigris_use_cache = TRUE)
marion_flows <- get_flows(
  geography = "county",
  state = "OR",
  county = "Marion",
  year = 2018,
  geometry = TRUE
  )

I want to directly as I can borrow this.

top_move_in <- marion_flows %>% 
  filter(!is.na(GEOID2), variable == "MOVEDIN") %>% 
  slice_max(n = 25, order_by = estimate) %>% 
  mutate(
    width = log(estimate),
    tooltip = paste0(
      scales::comma(estimate * 5, 1),
      " people moved from ", str_remove(FULL2_NAME, "Metro Area"),
      " to ", str_remove(FULL1_NAME, "Metro Area"), " between 2014 and 2018"
      )
    )
library(htmlwidgets)
# md <- 
top_move_in %>% 
  mapdeck(pitch = 45) %>% 
  add_arc(
    origin = "centroid1",
    destination = "centroid2",
    stroke_width = "width",
    auto_highlight = TRUE,
    highlight_colour = "#8c43facc",
    tooltip = "tooltip"
  )
## Registered S3 method overwritten by 'jsonify':
##   method     from    
##   print.json jsonlite
#frameWidget(md)