Skip to content

Instantly share code, notes, and snippets.

View andrewbtran's full-sized avatar

Andrew Tran andrewbtran

View GitHub Profile
@andrewbtran
andrewbtran / wpdatateam-ridge
Last active March 2, 2023 17:06
wpdatateam logo generator
# code from https://github.com/gkaramanis/aRtist/blob/main/genuary/2021/2021-3/2021-3.R
library(ggplot2)
library(dplyr)
library(magick)
library(ggridges)
# Read in image and convert to grayscale
img <- image_read(here::here("MRlWzfMH_400x400.jpg")) %>%
image_convert(colorspace = "gray")
@andrewbtran
andrewbtran / covid19_disparity_early.Rmd
Last active April 8, 2020 15:04
coronavirus county and regional disparity analysis
---
title: "Coronavirus racial disparities"
author: "Andrew Ba Tran and Reis Thebault"
date: "4/7/2020"
output:
html_document:
code_folding: hide
---
Counties where Black residents are the majority have three times the rate of median cases of coronavirus cases and have almost four times the average rate of deaths of counties.
@andrewbtran
andrewbtran / covidtracking_table.R
Last active March 23, 2020 23:27
covidtracking table
# This function checks if you don't have the correct packages installed yet
# If not, it will install it for you
packages <- c("tidyverse", "jsonlite", "data.table", "formattable", "scales", "knitr")
if (length(setdiff(packages, rownames(installed.packages()))) > 0) {
install.packages(setdiff(packages, rownames(installed.packages())), repos = "http://cran.us.r-project.org")
}
# packages necessary
library(tidyverse)
library(jsonlite)

Keybase proof

I hereby claim:

  • I am andrewbtran on github.
  • I am trana (https://keybase.io/trana) on keybase.
  • I have a public key ASAMUjcvhuYo-gflVNYHlsAzAXhR8uH3Ge2NvwOjh7TDMAo

To claim this, I am signing this object:

@andrewbtran
andrewbtran / nlpp.r
Last active December 16, 2019 22:31
NiemanLab Predictions Predictor
# Load libraries
library(dplyr)
library(rvest)
devtools::install_github("abresler/markovifyR")
library(markovifyR)
# The url for the 2019 predictions
year2019 <- "https://www.niemanlab.org/collection/predictions-2019"
@andrewbtran
andrewbtran / gsiterator.R
Created June 19, 2019 17:39
gsiterator template
library(tidyverse)
library(googlesheets)
# Authorize user on Google
gs_auth(new_user = TRUE)
# Naming the sheet
name_of_googlesheet <- "Testing out gsiterator"
# Test array
@andrewbtran
andrewbtran / gist:4bf3d8dd7a0f443f4888a31eaa7fff1b
Created April 29, 2019 14:32
Game of Thrones death pool (week 3 results)
library(tidyverse)
responses <- read_csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vT7yj6UE0S08spLamewjnZH1vbOCqobyRSEao5I535XvgO9VeM_fwe-P84_9oiPAuQsfd5rYyncNuax/pub?output=csv")
week3 <- data.frame(c("Theon Greyjoy",
"Melisandre",
"Jorah Mormont",
"Edd Tollett",
"Lyanna Mormont",
"Beric Dondarrion (can select multiple eps for death)
@andrewbtran
andrewbtran / financial-disclosure.R
Created August 31, 2018 19:05
Scraping WH financial disclosures
library(tidyverse)
library(rvest)
page <- xml2::read_html("https://extapps2.oge.gov/201/Presiden.nsf/PAS%20Filings%20by%20Date?OpenView")
tbl <- html_table(page)[[1]]
tbl <- as_tibble(tbl)
names(tbl) <- c("date", "report", "name", "department", "position")
tbl
@andrewbtran
andrewbtran / top_1_percent
Created August 3, 2018 19:43
top 1 percent ipums
# File # 1
# https://drive.google.com/open?id=1Lhz23JP4gRW4p_01D7OzaL60CT1wfem-
# File # 2
# https://drive.google.com/open?id=1XOWD8COTdDx30HNLZgrp57WzWUGOtaKA
# NOTE: To load data, you must download both the extract's data and the DDI
# and also set the working directory to the folder with these files (or change the path below).
#install.packages("tidyverse")
@andrewbtran
andrewbtran / gist:8507f79e0ded054ac2b38878f94063dc
Created July 27, 2018 17:21
new orleans schools for loop
library(jsonlite)
library(tidyr)
schools_list <- fromJSON("http://neworleansequityindex.org/jsoncache/schools.json")
schools_list <- schools_list$data
# for loop
# for i in 1 through number of rows of the dataframe schools_list