Libraries

Read CSV

Filter PA VSOs (NTEECC W30)

Examine Centre County (FIPS 42027)

Filter by VSO Type

Visualize Breakdown of PA VSO Types

Summarize

Map

Read merged cores .csv file

all_core_bind_csv <- read.csv("all_core_bind.csv")
all_core_bind_csv <- all_core_bind_csv %>%  
    mutate(EIN = as.character(EIN))
length(all_core_bind_csv$EIN)
## [1] 1312
#length(unique(all_core_bind_csv$EIN))

Big Six - American Legion, Veterans of Foreign Wars, Amvets, Disabled American Veterans, Vietnam Veterans, Paralyzed Veterans of America

American Legion

pa_vso_legion_core <- inner_join(pa_vso_legion, all_core_bind_csv, by = c("EIN"))
sprintf("# of rows included in core files: %s (of %s)", 
        nrow(pa_vso_legion_core),nrow(pa_vso_legion)
        )
## [1] "# of rows included in core files: 493 (of 523)"
pa_vso_legion

VFW

TOADD - FORD CITY VFW POST 4843 CLUBROOM- HOME ASSOCIATION INC VFW USA - VFW HOME & CLUB ASSN INC - VETERANS OF FOREIGN WARS CLUB & HOME ASSOCIATION

pa_vso_vfw_core <- inner_join(pa_vso_vfw, all_core_bind_csv, by = c("EIN"))
sprintf("# of rows included in core files: %s (of %s)", 
        nrow(pa_vso_vfw_core), nrow(pa_vso_vfw)
        )
## [1] "# of rows included in core files: 380 (of 582)"
pa_vso_vfw

American Veterans (Amvets)

pa_vso_amvets_core <- inner_join(pa_vso_amvets, all_core_bind_csv, by = c("EIN"))
sprintf("# of rows included in core files: %s (of %s)", 
        nrow(pa_vso_amvets_core), nrow(pa_vso_amvets)
        )
## [1] "# of rows included in core files: 29 (of 61)"
pa_vso_amvets

Disabled American Veterans

pa_vso_disamvets_core <- inner_join(pa_vso_disamvets, all_core_bind_csv, by = c("EIN"))
sprintf("# of rows included in core files: %s (of %s)", 
        nrow(pa_vso_disamvets_core), nrow(pa_vso_disamvets)
        )
## [1] "# of rows included in core files: 7 (of 44)"
pa_vso_disamvets

Vietnam Veterans of America

pa_vso_vietvetamer_core <- inner_join(pa_vso_vietvetamer, all_core_bind_csv, by = c("EIN"))
sprintf("# of rows included in core files: %s (of %s)", 
        nrow(pa_vso_vietvetamer_core), nrow(pa_vso_vietvetamer)
        )
## [1] "# of rows included in core files: 8 (of 30)"
pa_vso_vietvetamer

Paralyzed Veterans of America

pa_vso_paravets_core <- inner_join(pa_vso_paravets, all_core_bind_csv, by = c("EIN"))
sprintf("# of rows included in core files: %s (of %s)", 
        nrow(pa_vso_paravets_core), nrow(pa_vso_paravets)
        )
## [1] "# of rows included in core files: 2 (of 1)"
pa_vso_paravets

“Club” Organizations

sprintf("# of rows included in core files: %s (of %s)", 
        nrow(inner_join(pa_vso_club, all_core_bind_csv, by = c("EIN"))),
        nrow(pa_vso_club)
        )
## [1] "# of rows included in core files: 35 (of 29)"
pa_vso_club

“Home” Organizations

sprintf("# of rows included in core files: %s (of %s)", 
        nrow(inner_join(pa_vso_home, all_core_bind_csv, by = c("EIN"))),
        nrow(pa_vso_home)
        )
## [1] "# of rows included in core files: 178 (of 119)"
pa_vso_home

Marine Corps League

sprintf("# of rows included in core files: %s (of %s)", 
        nrow(inner_join(pa_vso_mcl, all_core_bind_csv, by = c("EIN"))),
        nrow(pa_vso_mcl)
        )
## [1] "# of rows included in core files: 10 (of 82)"
pa_vso_mcl

Other Non-Categorized

sprintf("# of rows included in core files: %s (of %s)", 
        nrow(inner_join(pa_vso_other, all_core_bind_csv, by = c("EIN"))),
        nrow(pa_vso_other)
        )
## [1] "# of rows included in core files: 201 (of 426)"
pa_vso_other

Map

make_map_data <- function(vso_data) {
  
  # Select columns of interest
  vso_data <- vso_data %>% select(EIN, NAME.x, SEC_NAME.x, CITY.x, STATE.x, ZIP, 
                                      FIPS.x, LATITUDE, LONGITUDE,CENSUSTRACT,
                                      SUBSECCD.x, ASSETS.x, INCOME.x, FIPS.x)
  
  # Just drop NAs, and empty strings for now
  vso_data <- vso_data %>% drop_na("LONGITUDE", "LATITUDE")
  vso_data <- vso_data[!(vso_data$LONGITUDE=="" | vso_data$LATITUDE==""),]
  
  # Geospatial
  vso_map_data <- vso_data %>%
    st_as_sf(
      coords = c("LONGITUDE", "LATITUDE"),
      crs = 4326
    )
  return(vso_map_data)
}
library(sf)
library(urbnmapr)
library(urbnthemes)
library(mapview)

# Subset by column
legion_map_data <- make_map_data(pa_vso_legion_core)
vfw_map_data <- make_map_data(pa_vso_vfw_core)
amvets_map_data <- make_map_data(pa_vso_amvets_core)
disamvets_map_data <- make_map_data(pa_vso_disamvets_core)
vietvetamer_map_data <- make_map_data(pa_vso_vietvetamer_core)
paravets_map_data <- make_map_data(pa_vso_paravets_core)

# Pennsylvania counties
pa_counties <- 
  get_urbn_map("counties", sf = TRUE) %>%
  filter(state_name %in% c("Pennsylvania"))  
## old-style crs object detected; please recreate object with a recent sf::st_crs()
# Create map
ggplot() +
  geom_sf(
    data = pa_counties,
    mapping = aes()
  ) +
  
  geom_sf(
  data = legion_map_data,
  mapping = aes(),
  color = palette_urbn_main["yellow"],
  size = 2.0
  ) +
  
  #geom_sf(
  #data = vfw_map_data,
  #mapping = aes(),
  #color = palette_urbn_main["yellow"],
  #size = 2.0
  #) +
  
  theme_urbn_map()

# Interactive map
mapview(legion_map_data, col.regions = c("blue")) +
  mapview(vfw_map_data, col.regions = c("red")) +
  mapview(amvets_map_data, col.regions = c("green")) +
  mapview(disamvets_map_data, col.regions = c("purple")) +
  mapview(vietvetamer_map_data, col.regions = c("yellow")) +
  mapview(paravets_map_data, col.regions = c("orange"))