This is the methodology used for the story: What do Connecticut residents borrow for from online lenders?

Visit the repo for the data used in this analysis or visit Kaggle’s data site for the Lending Club data and other scripts that analysts have submitted.

library(dplyr)
library(tidyr)
library(choroplethr)
library(stringr)
# devtools::install_github("hrbrmstr/ggalt")
library(ggplot2)
library(ggalt)
library(scales)

Mapping national data

loans <- read.csv("data/loan.csv", stringsAsFactors=FALSE)

us_map <- loans %>%
  group_by(addr_state) %>%
  dplyr::summarise(loans=n(), total=sum(loan_amnt), average=round(mean(loan_amnt),2))

# Bringing in US population
uspop <- read.csv("data/uspop.csv", stringsAsFactors=FALSE)

us_map <- left_join(us_map, uspop)
## Joining by: "addr_state"
# Adjusting per capita
us_map$loans_per_capita <- round(us_map$loans/us_map$population*10000,2)

us_map <- us_map[c("state", "loans_per_capita", "loans", "total", "average")]
us_map$state <- str_to_lower(us_map$state)
# loans per capita

lpc <- us_map[c("state", "loans_per_capita")]
colnames(lpc) <- c("region", "value")

state_choropleth(lpc, title = "Loans per 10,000 residents")