Skip to content

Instantly share code, notes, and snippets.

View walkerke's full-sized avatar

Kyle Walker walkerke

View GitHub Profile
library(idbr)
library(ggplot2)
library(dplyr)
library(gganimate)
library(animation)
idb_api_key("Your key goes here")
male <- idb1('NI', 1990:2050, sex = 'male') %>%
mutate(POP = POP * -1,
library(idbr)
library(dplyr)
library(ggplot2)
library(tidyr)
library(countrycode)
library(gganimate)
library(tweenr)
ctrys <- countrycode(c('South Africa', 'Botswana', 'Lesotho', 'Namibia', 'Zimbabwe', 'Swaziland'),
'country.name', 'fips104')
library(tigris)
us_states <- unique(fips_codes$state)[1:51]
us_places <- rbind_tigris(
lapply(
us_states, function(x) {
places(state = x, cb = TRUE)
}
)
# Write to a shapefile for loading into CartoDB
writeOGR(tad_merged, dsn = ".", layer = 'fw_parcels',
driver = 'ESRI Shapefile', overwrite_layer = TRUE)
summary(tad_merged$valsqft)
# Min. 1st Qu. Median Mean 3rd Qu. Max.
# 0.00 5.42 12.06 16.07 23.03 6345.00
quantile(tad_merged$valsqft, probs = seq(0, 1, 1/7))
# 0% 14.28571% 28.57143% 42.85714% 57.14286% 71.42857% 85.71429% 100%
# 0.00 2.97 6.24 9.83 15.05 21.55 27.91 6344.93
# Merge the TAD data to the parcels based on a common ID, and remove un-matched records
tad_merged <- geo_join(parcels, tad_sub, 'TAXPIN', 'GIS_Link', how = 'inner')
# Drop parcels with an area of 0, and calculate a "value/square foot" column
tad_merged <- tad_merged[tad_merged$CALCULATED != 0, ]
# Calculate value/square foot (converting acres to square feet)
tad_merged$valsqft <- round(tad_merged$Total_Value / (tad_merged$CALCULATED * 43560), 2)
# Load in the data with readOGR (warning: slow)
parcels <- readOGR(dsn = ".", layer = 'tad5ft', stringsAsFactors = FALSE)
# Drop undeveloped parcels and unneeded columns
parcels <- parcels[parcels$PARCELTYPE != 2, ]
parcels@data <- parcels@data[c('TAXPIN', 'CALCULATED')]
# Set your working directory in RStudio to your data/script directory
# Session > Set Working Directory > To Source File Location
# If necessary, first run
# install.packages(c('rgdal', 'readr', 'dplyr', 'tigris', 'ggplot2', 'scales'))
library(rgdal) # For loading spatial data
library(readr) # For loading tabular data
library(dplyr) # For processing tabular data
library(tigris) # For joining spatial and tabular data
library(idbr)
library(ggplot2)
library(animation)
library(dplyr)
library(gganimate)
idb_api_key("Your Census API key goes here")
male <- idb1('IN', 2000:2050, sex = 'male') %>%
mutate(POP = POP * -1,
library(tigris)
library(rgeos)
library(stringr)
library(leaflet)
# Pull the ZCTAs
zips <- zctas(cb = TRUE, starts_with = c('75', '76'))
plot(zips)