Non-Profits in Oregon: Socrata is Cool

Socrata: The Open Data Portal

I did not previously know much about precisely how open data portals had evolved. Oregon’s is quite nice and I will take the opportunity to map and summarise non-profits throughout the state. Here is the data.

library(RSocrata)
Oregon.Nonprofits <- read.socrata("https://data.oregon.gov/resource/8kyv-b2kw.csv")
glimpse(Oregon.Nonprofits)
## Rows: 163,489
## Columns: 18
## $ registry_number             <int> 299818, 299818, 299818, 299818, 299818, 5…
## $ business_name               <chr> "UNITED METHODIST CHURCH, OREGON CITY, OR…
## $ entity_type                 <chr> "DOMESTIC NONPROFIT CORPORATION", "DOMEST…
## $ registry_date               <chr> "1850-05-17 00:00:00", "1850-05-17 00:00:…
## $ nonprofit_type              <chr> "RELIGIOUS WITH MEMBERS", "RELIGIOUS WITH…
## $ associated_name_type        <chr> "MAILING ADDRESS", "PRESIDENT", "PRINCIPA…
## $ first_name                  <chr> "", "MIKE", "", "MIKE", "CHRISTA", "", "S…
## $ middle_name                 <chr> "", "", "", "", "", "", "E", "", "", "", …
## $ last_name                   <chr> "", "BENISCHEK", "", "BENISCHEK", "PALMER…
## $ suffix                      <chr> "", "", "", "", "", "", "", "", "", "", "…
## $ not_of_record_entity        <chr> "", "", "", "", "", "", "", "", "", "", "…
## $ entity_of_record_reg_number <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ entity_of_record_name       <chr> "", "", "", "", "", "", "", "", "", "", "…
## $ address                     <chr> "18955 S SOUTH END RD", "18955 S SOUTH EN…
## $ address_continued           <chr> "", "", "", "", "", "", "", "", "", "", "…
## $ city                        <chr> "OREGON CITY", "OREGON CITY", "OREGON CIT…
## $ state                       <chr> "OR", "OR", "OR", "OR", "OR", "OR", "OR",…
## $ zip_code                    <chr> "97045", "97045", "97045", "97045", "9704…

A basic zip code map

or_zips <- zctas(cb = TRUE, starts_with = "97", class="sf")
or_zips %>% ggplot(., aes(geometry=geometry, group=ZCTA5CE10)) + geom_sf()

Join a summary table by zip code.

I am not exactly sure why this happens. For whatever reason, the map always has missing chunks

ON <- Oregon.Nonprofits %>% group_by(zip_code) %>% summarise(Nonprofits = n_distinct(registry_number)) %>% ungroup()
Map.Me <- merge(or_zips, ON, by.x= "ZCTA5CE10", by.y = "zip_code")
Map.Me %>% ggplot(., aes(geometry=geometry, fill=Nonprofits)) + geom_sf() + scale_fill_viridis_c()

Some Summary

Oregon.Nonprofits %>% 
  group_by(nonprofit_type) %>% 
  summarise(count = n_distinct(registry_number)) %>% 
  ggplot(., aes(x=fct_reorder(stringr::str_wrap(nonprofit_type, 10), count), y=count, fill=nonprofit_type)) + 
  geom_col() + 
  scale_fill_viridis_d() + 
  coord_flip() + 
  labs(title="The Distribution of Oregon Non-Profits", fill="Type", x="") + 
  guides(fill=FALSE) + 
  theme_minimal()

# A Leaflet

library(tidyverse)
library(leaflet)
library(stringr)
library(sf)
library(here)
library(widgetframe)
library(htmlwidgets)
library(htmltools)
lf <- Map.Me %>% sf::st_transform(crs = '+proj=longlat +datum=WGS84') %>% leaflet() %>%
addPolygons(color = "#444444", weight = 1, smoothFactor = 0.5,
    opacity = 1.0, fillOpacity = 0.5,
    fillColor = ~colorQuantile("YlOrRd", Nonprofits)(Nonprofits),
    highlightOptions = highlightOptions(color = "white", weight = 2,
      bringToFront = TRUE))
frameWidget(lf)
Avatar
Robert W. Walker
Associate Professor of Quantitative Methods

My research interests include causal inference, statistical computation and data visualization.

Next
Previous

Related