Created
February 4, 2018 19:21
-
-
Save walkerke/93bfe80bb7735aa6265a61013eaed3fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidycensus) | |
library(plotly) | |
library(ggplot2) # devtools::install_github("tidyverse/ggplot2") | |
library(crosstalk) | |
# Set your Census API key with `census_api_key()` if not already installed | |
tx <- get_acs(geography = "county", | |
variables = c(pctcollege = "DP02_0067P", | |
hhincome = "DP03_0062"), | |
state = "TX", | |
geometry = TRUE, | |
output = "wide", | |
resolution = "20m") | |
tx_shared <- SharedData$new(tx, key = ~NAME) | |
scatter <- ggplot(tx_shared, aes(x = pctcollegeE, y = hhincomeE, label = NAME)) + | |
geom_point() + | |
labs(x = "Percent over 25 with a bachelor's degree or higher", | |
y = "Median household income", | |
title = "Counties in Texas (2012-2016 ACS)") | |
map <- ggplot(tx_shared, aes(label = NAME)) + | |
geom_sf(fill = "grey", color = "black") + | |
coord_sf(crs = 3083) # http://spatialreference.org/ref/epsg/nad83-texas-centric-albers-equal-area/ | |
scatterly <- ggplotly(scatter, tooltip = "NAME") %>% | |
layout(dragmode = "lasso") %>% | |
highlight("plotly_selected", color = "red") | |
maply <- ggplotly(map, tooltip = "NAME") %>% | |
highlight("plotly_selected", color = "red") | |
bscols(scatterly, maply) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment