Skip to contents
## Warning: package 'tigris' was built under R version 4.3.2
# Load data
data("test_data")
data("variable_list")

states = states()

Creating summaries by geographic variables using hts_summary

hts_summary can summarize geographic variables.

income_county_list = hts_prep_variable(
  summarize_var = "income_detailed",
  summarize_by = "home_county",
  data = test_data
)

output = hts_summary(
  prepped_dt = income_county_list$cat,
  summarize_var = "income_detailed",
  summarize_by = "home_county"
)

factorize_df(
  output$summary$unwtd,
  vals_df = value_labels,
  value_label_colname = "label"
)
##      home_county      income_detailed count       prop
##  1: Arike County        Under $10,000     8 0.02469136
##  2: Arike County      $10,000-$24,999    26 0.08024691
##  3: Arike County      $25,000-$34,999    11 0.03395062
##  4: Arike County      $35,000-$49,999    11 0.03395062
##  5: Arike County      $50,000-$74,999    40 0.12345679
##  6: Arike County      $75,000-$99,999    47 0.14506173
##  7: Arike County    $100,000-$149,999    56 0.17283951
##  8: Arike County    $150,000-$199,999    30 0.09259259
##  9: Arike County    $200,000-$249,999    24 0.07407407
## 10: Arike County     $250,000 or more    35 0.10802469
## 11: Arike County Prefer not to answer    36 0.11111111
## 12: Clark County        Under $10,000    12 0.03498542
## 13: Clark County      $10,000-$24,999    13 0.03790087
## 14: Clark County      $25,000-$34,999    16 0.04664723
## 15: Clark County      $35,000-$49,999    30 0.08746356
## 16: Clark County      $50,000-$74,999    42 0.12244898
## 17: Clark County      $75,000-$99,999    28 0.08163265
## 18: Clark County    $100,000-$149,999    60 0.17492711
## 19: Clark County    $150,000-$199,999    34 0.09912536
## 20: Clark County    $200,000-$249,999    24 0.06997085
## 21: Clark County     $250,000 or more    34 0.09912536
## 22: Clark County Prefer not to answer    50 0.14577259
## 23: Moore County        Under $10,000     9 0.02702703
## 24: Moore County      $10,000-$24,999    16 0.04804805
## 25: Moore County      $25,000-$34,999    15 0.04504505
## 26: Moore County      $35,000-$49,999    19 0.05705706
## 27: Moore County      $50,000-$74,999    56 0.16816817
## 28: Moore County      $75,000-$99,999    31 0.09309309
## 29: Moore County    $100,000-$149,999    61 0.18318318
## 30: Moore County    $150,000-$199,999    35 0.10510511
## 31: Moore County    $200,000-$249,999    29 0.08708709
## 32: Moore County     $250,000 or more    24 0.07207207
## 33: Moore County Prefer not to answer    38 0.11411411
##      home_county      income_detailed count       prop

Using join_spatial to join together separate shapefiles

join_spatial can link together multiple geographies.

hh = join_spatial(
  hh,
  dplyr::select(states, home_state = NAME),
  id_col = "hh_id",
  lon_col = "home_lon",
  lat_col = "home_lat",
  largest = TRUE
)

hh[, .N, home_state]
##         home_state   N
##  1:        Indiana  39
##  2:           Ohio  29
##  3:       Oklahoma 101
##  4:       Arkansas 111
##  5:         Kansas 118
##  6:      Tennessee  78
##  7: North Carolina  36
##  8:       Missouri 106
##  9:       Kentucky  66
## 10:        Alabama  42
## 11:       Illinois  59
## 12: South Carolina  37
## 13:          Texas  50
## 14:    Mississippi  43
## 15:        Georgia  28
## 16:       Virginia  16
## 17:  West Virginia  40
## 18:       Nebraska   1