Skip to content

Instantly share code, notes, and snippets.

View svmiller's full-sized avatar
🤷‍♂️
¯\_(ツ)_/¯

Steven V. Miller svmiller

🤷‍♂️
¯\_(ツ)_/¯
View GitHub Profile
GSS <- readRDS("~/Dropbox/data/gss/gss7216-r1a.rds")
library(tidyverse)
library(stevemisc)
GSS %>%
select(year, id, race, partyid, marblk:marhisp) %>%
filter(year >= 1990) %>%
filter(race == 1 & partyid != 7) %>%
mutate(partisanship = NA,
library(babynames)
library(stevemisc)
library(tidyverse)
babynames %>%
filter(name == "Jolene" & sex == "F") %>%
mutate(date = lubridate::ymd(year, truncated = 2L)) %>%
ggplot(.,aes(date, n)) + theme_steve_web2() +
scale_y_continuous(labels = scales::comma) +
geom_ribbon(aes(ymin=-Inf, ymax=n),
@svmiller
svmiller / unsc-vetoes.csv
Last active February 7, 2019 01:36
UN Security Council Vetoes, 1946-2018
Date Draft Record Agenda Item Issue (Recoded) State All Veto States
1 June 2018 S/2018/516 S/PV.8274 Middle East situation, including the Palestinian question Israel/Palestine USA USA
10 April 2018 S/2018/321 S/PV.8228 Middle East Syria USSR/Russia Russian Federation
26 February 2018 S/2018/156 S/PV.8190 Middle East Syria USSR/Russia Russian Federation
18 December 2017 S/2017/1060 S/PV.8139 Middle East situation, including the Palestinian question Israel/Palestine USA USA
17 November 2017 S/2017/970 S/PV.8107 Middle East Syria USSR/Russia Russian Federation
16 November 2017 S/2017/962 S/PV.8105 Middle East Syria USSR/Russia Russian Federation
24 October 2017 S/2017/884 S/PV.8073 Middle East Syria USSR/Russia Russian Federation
12 April 2017 S/2017/315 S/PV.7922 Middle East Syria USSR/Russia Russian Federation
28 February 2017 S/2017/172 S/PV.7893 Middle East Syria China ChinaRussian Federation
@svmiller
svmiller / number-of-brandys-1945-2017.R
Created January 28, 2019 16:36
🎶 The sailors say "Brandy, you're a fine girl (you're a fine girl), what a good wife you would be (such a fine girl)..." 🎶
library(babynames)
babynames %>%
filter(name == "Brandy" & sex =="F") %>%
mutate(date = lubridate::ymd(year, truncated = 2L)) %>%
ggplot(.,aes(date, n)) + geom_line() +
theme_steve_web() +
scale_y_continuous(labels = scales::comma) +
annotate("text",
x = as.Date("1972-01-18"), y = 6000,
size = 3,
@svmiller
svmiller / write-sqlite-db-in-r.R
Last active January 23, 2019 19:34
A note to self on creating an empty .db file and populating as an sqlite database in R.
library(RSQLite)
library(babynames)
# note to self: create myfancysqlite.db as an empty .txt file (with the extension, tho).
connection <- dbConnect(SQLite(), "myfancysqlite.db")
dbWriteTable(connection, "mtcars", mtcars)
dbWriteTable(connection, "babydat", babynames)
dbDisconnect(connection)
user.self sys.self elapsed user.child sys.child Method
0.2600000000001046 0.012999999999998124 0.2869999999998072 0 0 dplyr::src_sqlite()
0.04200000000003001 0.001999999999995339 0.053999999999632564 0 0 dplyr::src_sqlite()
0.014000000000010004 0 0.014000000000123691 0 0 dplyr::src_sqlite()
0.013000000000033651 0 0.012999999999919964 0 0 dplyr::src_sqlite()
0.01599999999996271 9.999999999976694e-4 0.016999999999825377 0 0 dplyr::src_sqlite()
0.01700000000005275 9.999999999976694e-4 0.01900000000023283 0 0 dplyr::src_sqlite()
0.012000000000057298 0 0.012000000000170985 0 0 dplyr::src_sqlite()
0.013000000000033651 0 0.012999999999919964 0 0 dplyr::src_sqlite()
0.014000000000010004 0 0.01499999999987267 0 0 dplyr::src_sqlite()
setwd("~/Dropbox/data/wvs")
library(tidyverse)
# sqlite method -----
# -------------------
sqlite_times = data.frame()
for(i in 1:10) {
main_call = system.time(WVS <- tbl(db <- src_sqlite(path = "wvs6wave.db"), "WVS"))
library(stevemisc)
library(tidyverse)
ggplot() +
geom_line(data = cpi_various_items, aes(date, cpi, color = Category), size=1.1) +
theme_steve_web2() +
guides(color = FALSE) +
geom_hline(yintercept = 100, linetype = "dashed") +
scale_x_date(limits = as.Date(c("2000-01-01","2020-01-01")),
@svmiller
svmiller / steves-clothes-example.R
Created January 7, 2019 00:06
Plot my clothes, by country of origin/type.
# This is just for an internal note to self. I'm going to touch this up a bit for presentation.
library(stevemisc)
steves_clothes %>%
group_by(origin, type) %>% summarize(ntype = n()) %>%
group_by(origin) %>% mutate(n = sum(ntype)) %>%
ggplot(.,aes(reorder(origin, -n), ntype)) + theme_steve_web() +
geom_bar(stat="identity",aes(fill=type), color="black") +
xlab("Country of Origin") + ylab("Number of Articles of Clothing in Steve's Closet") +
labs(title = "Where Do Steve's Clothes Come From?",
library(fredr)
library(stevemisc)
library(tidyverse)
fredr(series_id = "UNRATE",
observation_start = as.Date("2013-09-01")) %>%
rename(unrate = value) %>%
ggplot(.,aes(date, unrate)) + geom_line() +
theme_steve_web2() +