Skip to content

Instantly share code, notes, and snippets.

@jshannon75
jshannon75 / elevation_map.md
Created September 29, 2019 20:11
Making a map of road elevation change for biking in Athens, Georgia

Creating a road elevation map in R

Jerry Shannon

This gist describes the process of calculating elevation change for roads in Athens-Clarke County, Georgia. This analysis is part of a process of creating a bike map for the county. As part of identifying the most bike (and walk) friendly routes, I and a student wanted to identify roads with the greatest elevation change.

Downloading OSM data

@jshannon75
jshannon75 / osmmap.R
Created November 15, 2019 20:49
Creating a WordCloud from OpenStreetMap in rstats using wordcloud2
library(tidyverse)
library(osmdata)
library(sf)
library(tigris)
library(wordcloud2)
library(tmap)
#Load city outline
city="Atlanta"
@jshannon75
jshannon75 / osmmap.R
Created November 15, 2019 20:49
Creating a WordCloud from OpenStreetMap in rstats using wordcloud2
library(tidyverse)
library(osmdata)
library(sf)
library(tigris)
library(wordcloud2)
library(tmap)
#Load city outline
city="Atlanta"
@jshannon75
jshannon75 / meancenterweights
Created November 25, 2019 01:36
Calculating state mean centers in R
library(tidyverse)
library(sf)
#Join population data to tract boundaries and convert to point coordinates
tractdata<-read_csv("nhgis0105_2017_tract_racepov.csv") #Data on population downloaded from NHGIS
tracts<-st_read("nhgis0101_shapefile_tl2017_us_tract_2017/US_tract_2017.shp",stringsAsFactors=FALSE) %>% #Tract boundaries downloaded from NHGIS
st_transform(4326)
tract_center<-tracts %>%
st_centroid() %>%
st_coordinates() %>%
from os import path
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import os
from wordcloud import WordCloud, STOPWORDS
d = path.dirname(__file__) if "__file__" in locals() else os.getcwd()
@jshannon75
jshannon75 / covid_gifmap
Created April 8, 2020 01:52
Creating a county level map of county growth rate/doubling time using R & tmap
library(tidyverse)
library(ggrepel)
library(gghighlight)
library(tidycensus)
library(sf)
dailydata<-read_csv("https://github.com/nytimes/covid-19-data/raw/master/us-counties.csv")
#This next step requires a census API
cty_pop<-get_acs(geography="county",variables = "B01001_001",geometry=TRUE) %>%
@jshannon75
jshannon75 / covdata_gifmap
Created May 26, 2020 16:53
Making a gif of county level mobility data using the covdata package
library(tidyverse)
library(covdata)
library(tmap)
library(TTR)
ga_mobility<-apple_mobility %>%
filter(sub_region=="Georgia" & geo_type=="county" &
is.na(index)==FALSE) %>%
group_by(region) %>%
mutate(ra = runMean(index, 5)) %>% ###Create a five day moving average
@jshannon75
jshannon75 / housingindex
Created June 4, 2020 17:39
Creating a housing vulnerability index using tidycensus
library(tidycensus)
library(tidyverse)
library(sf)
#Select variables
v18<-load_variables(2018,"acs5",cache=TRUE)
vars<-v18 %>%
filter(substr(name,1,6) %in% c("B25064","B03002","B25106","B19013"))
#write_csv(vars,"data/census_vars.csv") #Select just those variables I want
vars_sel<-read_csv("data/census_vars.csv")
@jshannon75
jshannon75 / wh_tsp
Created November 2, 2021 13:18
Waffle House: TSP map
#Code adapted from https://github.com/datawookie/travelling-salesman-map/blob/master/travelling-salesman-demo.R
library(tidyverse)
library(purrr)
library(ggmap)
library(gmapsdistance)
library(TSP)
library(sf)
# Due to changes in the Google Maps Terms of Service, this code will not work without first registering an API key.
library(tidyverse)
library(extrafont)
library(sf)
ebird<-read_csv("ebird_GA_Sep2019.csv") #Individual observation data
species<-ebird %>%
distinct(`COMMON NAME`)
species_blue<-species %>%
filter(str_detect(tolower(`COMMON NAME`),"blue"))