Skip to content

Instantly share code, notes, and snippets.

View ryanrosenberg's full-sized avatar
🏀

Ryan Rosenberg ryanrosenberg

🏀
  • Palo Alto, CA
View GitHub Profile
---
title: "Making Interactive Maps of Public Data in R"
author: "Ryan Rosenberg"
output: html_document
---
<style>
.leaflet {
margin: auto;
}
</style>
library(tidyverse)
library(sf)
library(lubridate)
chicago_neighborhoods <- read_sf("chi_community_shapefiles") %>%
mutate(community_area = as.integer(area_numbe))
chicago_potholes <- read_csv("chicago_potholes.csv") %>%
janitor::clean_names() %>%
mutate_at(vars(creation_date, completion_date), mdy) %>%
mutate(time_to_fill = difftime(completion_date, creation_date))
library(tidyverse)
regs_tossups <- read_tsv("tossups.tsv")
regs_games_played <- regs_tossups %>%
filter(!is.na(team), packet != "S", !is.na(buzz_location_pct)) %>%
distinct(team, packet) %>%
count(team)
# Change based on set categories
@ryanrosenberg
ryanrosenberg / tribune_trivia_map.R
Created August 22, 2018 03:10
code for making a map from the Tribune's trivia guide
library(tidyverse)
library(rvest)
library(leaflet)
library(mapsapi)
trivia <- "http://www.chicagotribune.com/redeye/culture/ct-redeye-do-trivia-chicago-bars-20180320-story.html"
bars <- read_html(trivia) %>%
html_nodes("a strong") %>%
html_text()
@ryanrosenberg
ryanrosenberg / riddler_express_date_vandals.R
Created April 8, 2018 22:10
Solution for Riddler Express 4/8/18
library(tidyverse)
month_vec <- c(rep(1, 31),
rep(2, 28),
rep(3, 31),
rep(4, 30),
rep(5, 31),
rep(6, 30),
rep(7, 31),
rep(8, 31),
library(tidyverse)
#### clear workspace ####
rm(list=ls())
#### read in the html file and clean up the data ####
msgs <- readLines("~/Documents/gosschat.html")
msgs <- gsub(" ", msgs, replacement="__")
msgs <- gsub("\"", msgs, replacement="##")
msgs <- gsub("\'", msgs, replacement="##")
library(tidyverse)
buzzes <- read_csv("~/Desktop/regs analysis/all_buzzes.csv")
tossups_heard <- read_csv("~/Desktop/regs analysis/tossups_heard.csv") %>%
filter(!is.na(Packet)) %>%
group_by(Packet) %>%
summarize(Heard = max(Heard))
tossups <- buzzes %>%