Skip to content

Instantly share code, notes, and snippets.

View ericpgreen's full-sized avatar

Eric Green ericpgreen

View GitHub Profile
This file has been truncated, but you can view the full file.
structure(list(GEOID = c("06001", "06003", "06005", "06007",
"06009", "06011", "06013", "06015", "06017", "06019", "06021",
"06023", "06025", "06027", "06029", "06031", "06033", "06035",
"06037", "06039", "06041", "06043", "06045", "06047", "06049",
"06051", "06053", "06055", "06057", "06059", "06061", "06063",
"06065", "06067", "06069", "06071", "06073", "06075", "06077",
"06079", "06081", "06083", "06085", "06087", "06089", "06091",
"06093", "06095", "06097", "06099", "06101", "06103", "06105",
"06107", "06109", "06111", "06113", "06115"), NAME = c("Alameda County, California",
"Alpine County, California", "Amador County, California", "Butte County, California",
@ericpgreen
ericpgreen / animate.R
Last active May 1, 2020 11:30
animate
library(tidyverse)
library(countrycode) # install.packages("countrycode")
# get the data
cases_wide <- read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv", stringsAsFactors = FALSE)
# pivot longer
cases <-
cases_wide %>%
# sum subnational data to get national totals
df_plot <- structure(list(Country.Region = structure(c(10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
df_mi <- structure(list(v1 = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L,
24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L,
37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L,
50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L,
63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L,
76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L,
89L, 90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L,
41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 91L, 92L, 93L,
94L, 95L, 96L, 97L, 98L, 99L, 100L, 41L, 42L, 43L, 44L, 45L,
library(modeldata)
data("stackoverflow")
library(tidyverse)
library(tidymodels)
set.seed(100) # Important!
# make smaller to save time
so_split <- initial_split(sample_n(stackoverflow, size = 300),
strata = Remote)
dat <- structure(list(as_areaK2 = c(1.80600428124798, 0.540755162151071,
1.11380561798778, 0.905008535194981, 1.51030279174279, 1.62818277069323,
0.547670625847753, 0.423004007838352, 1.46253516403771, 0.356614193846387,
1.32537997345858, 1.97943199845685, 0.704586252581037, 5.43783602151111,
0.295972731390631, 0.569928566697037, 2.00102994158912, 0.536332014583354,
1.09615798927973, 0.614294565789438, 1.43053345446891, 0.290749391275211,
0.835675266761967, 1.769093703832, 0.168990657300447, 1.24986815028974,
1.13883574377182, 0.168090567405105, 0.817897846292054, 0.401271690522274,
0.290621172764002, 0.712438998211716, 0.783548316264122, 0.650124767482093,
0.0797067856323663, 0.806036492389197, 0.117758252729661, 0.402213489166873,
zones <- structure(list(Id = c(0L, 0L, 0L, 0L), LocationID = c(10, 20,
30, 40), geometry = structure(list(structure(list(structure(c(34.0801799264875,
34.080295586826, 34.0804625363008, 34.080629560025, 34.0805268621977,
34.0805269199715, 34.0806296631948, 34.0806682414381, 34.0806426051738,
34.0806940056932, 34.0809252151302, 34.0810793258357, 34.0812462918301,
34.0813233079207, 34.0812847379028, 34.0814003074831, 34.0815801246098,
34.0816828223496, 34.081657070448, 34.0816955495712, 34.0819138540295,
34.0821835548344, 34.0822606493965, 34.0824661687807, 34.0826460147848,
34.0827102954327, 34.0826589776298, 34.0826847337602, 34.0828131916925,
34.0829416579086, 34.0830059220743, 34.083121487434, 34.0832755980364,
@ericpgreen
ericpgreen / points
Last active January 22, 2020 15:55
points<- structure(list(Id = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
@ericpgreen
ericpgreen / timeseries.R
Created June 18, 2019 13:28
time series
# @ericpgreen
# CausalImpact
library(CausalImpact)
set.seed(1)
x1 <- 24 + arima.sim(model = list(ar = 0.999), n = 24)
y <- 1.2 * x1 + rnorm(24)
y[13:24] <- y[13:24] + 10
data <- cbind(y, x1)
@ericpgreen
ericpgreen / owid.R
Created June 14, 2019 08:33
Visualizing OWID plot as slope chart
# Visualizing OWID plot as slope chart
# @ericpgreen
# original: https://ourworldindata.org/does-the-news-reflect-what-we-die-from?linkId=68864855
library(tidyverse)
library(ggrepel)
library(viridis)
#library(RColorBrewer)