Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

# data source: http://web.mta.info/developers/turnstile.html
library(ggplot2)
library(dplyr)
library(tidyr)
library(readr)
# define read function with schema ----
read_data <- function(url) {
readr::read_csv(url,
@emilyriederer
emilyriederer / cta-covid.R
Last active May 17, 2020 22:27
Examining Chicago CTA traffic by stop in the week following Illinois' COVID-19 stay-at-home order, superimposed over ACS tract-level median income estimates
# load packages ----
library(RSocrata)
library(tidycensus)
library(dplyr)
library(mapview)
library(leaflet)
library(sp)
# read & wrangle turnstile data ----
stations <- read.socrata("https://data.cityofchicago.org/resource/8pix-ypme.json")
@emilyriederer
emilyriederer / last-bullet-highlight-demo.html
Created May 27, 2019 16:03
Simple CSS to emphasize the last item in a list. Potentially useful for xaringan slides.
<html>
<body>
<style>
li {
color: gray;
}
.last-highlight>li:last-of-type {
color: black;
}
@emilyriederer
emilyriederer / ugliest-ggplot-theme.R
Last active May 11, 2023 06:35
A very, very ugly ggplot2 to demonstrate the wide variety of ggplot2 theme() options
library(ggplot2)
# sample data for plot ----
points <-
data.frame(
x = rep(1:10,3),
y = rep(1:10,3),
z = sort(rep(letters[1:2], 15)),
w = rep(letters[3:4], 15)
)
# ggplot using many theme options ----
@emilyriederer
emilyriederer / dynamic-tabset-colors.Rmd
Last active August 3, 2022 09:37
Generate <style> block of CSS to change tabset colors by a condition
---
title: "Untitled"
author: "Emily Riederer"
date: "5/15/2019"
output: html_document
---
```{r}
# dummy data
data <- data.frame(
@emilyriederer
emilyriederer / test_sxss.R
Created February 27, 2019 11:29
knitr eng_sxss unit tests
library(testthat)
# define code chunks ----
scss <- c("$font-stack: Helvetica, sans-serif;", "$primary-color: #333;",
"", "body {", " font: 100% $font-stack;", " color: $primary-color;",
"}")
sass <- c("$font-stack: Helvetica, sans-serif", "$primary-color: #333",
"", "body", " font: 100% $font-stack", " color: $primary-color")
output_compressed <- '<style type=\"text/css\">\nbody{font:100% Helvetica,sans-serif;color:#333}\n</style>\n'