%>%
household_credit mutate(date = year %>% paste0("-01-01") %>% as.Date) %>%
spread(variable, value) %>%
mutate(mortgage_total = mortgage*population) %>%
group_by(date) %>%
summarise(mortgage_total = sum(mortgage_total) / 10^9) %>%
ggplot(.) + geom_line(aes(x = date, y = mortgage_total)) +
theme_minimal() + xlab("") + ylab("") +
scale_x_date(breaks = seq(1870, 2020, 1) %>% paste0("-01-01") %>% as.Date,
labels = date_format("%y")) +
scale_y_continuous(breaks = seq(2000, 10000, 1000),
labels = dollar_format(suffix = "Bn", prefix = "$"))
%>%
household_credit filter(variable == "mortgage",
== 2007) %>%
year select(county_code = fips, value) %>%
left_join(county_code_name %>%
select(county_code, subregion = county_name3, region = state_name3),
by = "county_code") %>%
right_join(county,
by = c("region", "subregion")) %>%
ggplot(aes(long, lat, group = group)) +
geom_polygon(aes(fill = value), colour = alpha("black", 1/2), size = 0.2) +
scale_fill_viridis_c(labels = scales::dollar_format(accuracy = 1),
na.value = "white",
breaks = c(25000, 50000, 75000, 100000, 125000)) +
theme_void() +
theme(legend.position = c(0.9, 0.2)) +
labs(fill = "Per Capita\nMortgage Debt")
%>%
household_credit filter(variable == "mortgage",
== 2006) %>%
year select(county_code = fips, value) %>%
left_join(county_code_name %>%
select(county_code, subregion = county_name3, region = state_name3),
by = "county_code") %>%
right_join(county %>%
filter(region == "california"),
by = c("region", "subregion")) %>%
ggplot(aes(long, lat, group = group)) +
geom_polygon(aes(fill = value), colour = alpha("black", 1/2), size = 0.2) +
scale_fill_viridis_c(na.value = "white",
labels = scales::dollar_format(accuracy = 1)) +
theme_void() + theme(legend.position = c(0.9, 0.8)) +
labs(fill = "Per Capita\nMortgage Debt") + coord_fixed(ratio = 1)
%>%
household_credit filter(variable == "mortgage",
== 2006) %>%
year select(county_code = fips, value) %>%
left_join(county_code_name %>%
select(county_code, subregion = county_name3, region = state_name3),
by = "county_code") %>%
right_join(county %>%
filter(region == "vermont"),
by = c("region", "subregion")) %>%
ggplot(aes(long, lat, group = group)) +
geom_polygon(aes(fill = value), colour = alpha("black", 1/2), size = 0.2) +
scale_fill_viridis_c(na.value = "white",
labels = scales::dollar_format(accuracy = 1)) +
theme_void() + theme(legend.position = c(1, 0.4)) +
labs(fill = "Per Capita\nMortgage Debt") + coord_fixed(ratio = 1)
%>%
household_credit filter(variable == "mortgage",
== 2006) %>%
year select(county_code = fips, value) %>%
left_join(county_code_name %>%
select(county_code, subregion = county_name3, region = state_name3),
by = "county_code") %>%
right_join(county %>%
filter(region == "texas"),
by = c("region", "subregion")) %>%
ggplot(aes(long, lat, group = group)) +
geom_polygon(aes(fill = value), colour = alpha("black", 1/2), size = 0.2) +
scale_fill_viridis_c(na.value = "white",
labels = scales::dollar_format(accuracy = 1)) +
theme_void() + theme(legend.position = c(0.05, 0.2)) +
labs(fill = "Per Capita\nMortgage Debt") + coord_fixed(ratio = 1)
%>%
household_credit filter(variable == "mortgage",
== 2006) %>%
year select(county_code = fips, value) %>%
left_join(county_code_name %>%
select(county_code, subregion = county_name3, region = state_name3),
by = "county_code") %>%
right_join(county %>%
filter(region == "massachusetts"),
by = c("region", "subregion")) %>%
ggplot(aes(long, lat, group = group)) +
geom_polygon(aes(fill = value), colour = alpha("black", 1/2), size = 0.2) +
scale_fill_viridis_c(na.value = "white",
labels = scales::dollar_format(accuracy = 1)) +
theme_void() + theme(legend.position = c(0.2, 0.2)) +
labs(fill = "Per Capita\nMortgage Debt") + coord_fixed(ratio = 1)