Small changes.
This commit is contained in:
@ -1,73 +1,73 @@
|
|||||||
|
|
||||||
# This project is to try to figure out similarity among
|
# This project is to try to figure out similarity among
|
||||||
# Grand Forks/East Grand Forks and US cities of similar size
|
# Grand Forks/East Grand Forks and US cities of similar size
|
||||||
# in similar climate. The results will then be used to reseearch
|
# in similar climate. The results will then be used to reseearch
|
||||||
# what those cities are doing for bike infra and how it is
|
# what those cities are doing for bike infra and how it is
|
||||||
# working out for them.
|
# working out for them.
|
||||||
|
|
||||||
# TODO make this Rmd file
|
# TODO make this Rmd file
|
||||||
|
|
||||||
library(tidycensus)
|
library(tidycensus)
|
||||||
library(tidyverse)
|
library(tidyverse)
|
||||||
library(ggplot2)
|
library(ggplot2)
|
||||||
library(tigris)
|
library(tigris)
|
||||||
library(viridis)
|
library(viridis)
|
||||||
library(ini)
|
library(ini)
|
||||||
library(sf)
|
library(sf)
|
||||||
# Load the census API key, the ini file should be of format
|
# Load the census API key, the ini file should be of format
|
||||||
# [keys]
|
# [keys]
|
||||||
# key = your_key_here
|
# key = your_key_here
|
||||||
census_api_key(read.ini('census_api_key.ini')$keys$key)
|
census_api_key(read.ini('census_api_key.ini')$keys$key)
|
||||||
|
|
||||||
# Get a list of variables
|
# Get a list of variables
|
||||||
vars <- load_variables("2018", "acs5")
|
vars <- load_variables("2018", "acs5")
|
||||||
|
|
||||||
# This includes a broader area
|
# This includes a broader area
|
||||||
# us_metro <- get_acs(geography = "metropolitan statistical area/micropolitan statistical area",
|
# us_metro <- get_acs(geography = "metropolitan statistical area/micropolitan statistical area",
|
||||||
# variables = "B01001_001",
|
# variables = "B01001_001",
|
||||||
# geometry = T)
|
# geometry = T)
|
||||||
# This is just urban
|
# This is just urban
|
||||||
# Code is for total population, all ages
|
# Code is for total population, all ages
|
||||||
# https://www.census.gov/data/developers/data-sets/acs-1year/notes-on-acs-api-variable-formats.html
|
# https://www.census.gov/data/developers/data-sets/acs-1year/notes-on-acs-api-variable-formats.html
|
||||||
us_urban <- get_acs(geography = "urban area",
|
us_urban <- get_acs(geography = "urban area",
|
||||||
variables = "B01001_001")
|
variables = "B01001_001")
|
||||||
|
|
||||||
# Geometry is not in tidycensus yet, so we have to get it this way
|
# Geometry is not in tidycensus yet, so we have to get it this way
|
||||||
# Download it once and save locally
|
# Download it once and save locally
|
||||||
#urban_areas_geom <- urban_areas(class = "sf")
|
#urban_areas_geom <- urban_areas(class = "sf")
|
||||||
#save(urban_areas_geom, file = "data/urban_areas_tigris.RData")
|
#save(urban_areas_geom, file = "data/urban_areas_tigris.RData")
|
||||||
# Load saved variable
|
# Load saved variable
|
||||||
load("data/urban_areas_tigris.RData")
|
load("data/urban_areas_tigris.RData")
|
||||||
|
|
||||||
us_urban_joined <- left_join(urban_areas_geom,
|
us_urban_joined <- left_join(urban_areas_geom,
|
||||||
us_urban,
|
us_urban,
|
||||||
by = c("GEOID10" = "GEOID"))
|
by = c("GEOID10" = "GEOID"))
|
||||||
|
|
||||||
# Prove you can plot the largest cities
|
# Define range of populations to include
|
||||||
ggplot(us_urban_joined %>% filter(estimate > 5000000)) +
|
gfk_pop <- us_urban_joined %>%
|
||||||
geom_sf(aes(fill = estimate),
|
filter(NAME == "Grand Forks, ND--MN Urbanized Area (2010)") %>%
|
||||||
color = NA) +
|
mutate(high = estimate + (estimate * 0.1),
|
||||||
theme_minimal() +
|
low = estimate - (estimate * 0.1))
|
||||||
scale_fill_viridis()
|
|
||||||
|
# Clean data
|
||||||
# Define range of populations to include
|
us_urban_clean <- us_urban_joined %>%
|
||||||
gfk_pop <- us_urban_clean %>%
|
select(NAME, variable, estimate, moe) %>%
|
||||||
filter(NAME == "Grand Forks, ND--MN Urbanized Area (2010)") %>%
|
st_centroid() %>%
|
||||||
mutate(high = estimate + (estimate * 0.1),
|
filter(estimate < gfk_pop[['high']],
|
||||||
low = estimate - (estimate * 0.1))
|
estimate > gfk_pop[['low']])
|
||||||
|
|
||||||
# Clean data
|
plot(us_urban_clean['estimate'])
|
||||||
us_urban_clean <- us_urban_joined %>%
|
|
||||||
select(NAME, variable, estimate, moe) %>%
|
ggplot(us_urban_clean) +
|
||||||
st_centroid() %>%
|
geom_sf(aes(color = estimate)) +
|
||||||
filter(estimate < gfk_pop[['high']],
|
scale_color_viridis() +
|
||||||
estimate > gfk_pop[['low']])
|
theme_minimal()
|
||||||
|
|
||||||
# TODO bring in climate data
|
# TODO bring in climate data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user