Skip to content

Instantly share code, notes, and snippets.

@jshannon75
jshannon75 / walkerwarnock_2022.csv
Created November 12, 2022 18:53
Animated Cartogram of the Nov 2022 Georgia Senate election
US Senate (Vote For 1)
Herschel Junior Walker (Rep) Raphael Warnock (I) (Dem) Chase Oliver (Lib)
County Registered Voters Election Day Votes Absentee by Mail Votes Advance Voting Votes Provisional Votes Total Votes Election Day Votes Absentee by Mail Votes Advance Voting Votes Provisional Votes Total Votes Election Day Votes Absentee by Mail Votes Advance Voting Votes Provisional Votes Total Votes Total
Appling 0 2569 224 2550 0 5343 411 155 694 0 1260 28 4 33 0 65 6668
Atkinson 0 866 33 807 0 1706 189 22 291 0 502 15 2 10 0 27 2235
Bacon 0 829 74 2301 0 3204 134 41 283 0 458 17 6 25 0 48 3710
Baker 0 352 35 322 2 711 163 87 272 4 526 7 0 4 1 12 1249
Baldwin 0 2717 296 4403 0 7416 2163 818 4343 0 7324 107 20 87 0 214 14954
Banks 0 2275 186 3887 0 6348 242 84 446 0 772 71 11 77 0 159 7279
Barrow 0 8934 662 10531 0 20127 3007 691 4534 0 8232 450 43 400 0 893 29252
library(tidyverse)
library(tmap)
library(sf)
ctytax<-read_csv("countyinflow1920.csv") %>%
mutate(ctyfips1=paste(y1_statefips,y1_countyfips,sep=""),
ctyfips2=paste(y2_statefips,y2_countyfips,sep=""))
counties<-tigris::counties()
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"))
@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.
@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 / 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 / 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) %>%
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 / 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() %>%
@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"