Skip to content

Instantly share code, notes, and snippets.

View aaronschiff's full-sized avatar

Aaron Schiff aaronschiff

View GitHub Profile
@aaronschiff
aaronschiff / make-timetable.R
Created April 18, 2018 00:35
Make a Japanese-style timetable using AT public transport data
# Make a Japanese-style timetable using AT public transport data
# You'll need to download AT's GTFS data file first from https://at.govt.nz/about-us/at-data-sources/google-transit-feed/
library(magrittr)
library(tidyverse)
library(hms)
library(lubridate)
library(stringr)
library(ggthemes)
@aaronschiff
aaronschiff / make-timetable-better.R
Created April 18, 2018 03:15
Make a Japanese-style timetable using AT timetable data (better version)
# Make a Japanese-style timetable using AT public transport data (better version)
# You'll need to download AT's GTFS data file first from https://at.govt.nz/about-us/at-data-sources/google-transit-feed/
library(magrittr)
library(tidyverse)
library(hms)
library(lubridate)
library(stringr)
library(ggthemes)
@aaronschiff
aaronschiff / gather-unite-spread.R
Created January 10, 2019 00:03
Example of gather-unite-spread data reshaping in R
library(tidyverse)
example_dat <- tribble(
~year, ~group, ~revenues, ~costs,
2015, "Apple", 1000, 500,
2016, "Apple", 1500, 600,
2017, "Apple", 1200, 550,
2015, "Pear", 2000, 1100,
2016, "Pear", 2500, 1300,
2017, "Pear", 2900, 1500,
@aaronschiff
aaronschiff / business-confidence.R
Last active August 7, 2019 22:08
GDP vs business confidence correlation
# Setup
library(conflicted)
library(tidyverse)
library(lubridate)
library(readxl)
conflict_prefer("filter", "dplyr")
conflict_prefer("lag", "dplyr")
conflict_prefer("lead", "dplyr")
@aaronschiff
aaronschiff / fixed-geom-chart.R
Created June 10, 2022 01:02
Create geom_tile chart with tiles of fixed size
# The objective is to make a faceted ggplot 'heatmap' with geom_tile where the
# rendered tiles in the output PNG file have a fixed width and height,
# regardless of whatever else is in the chart.
# When ggplot charts are built, the height and width of all components are
# predetermined *except* for the facet panels. Thus the approach here is to
# render an initial version of the chart to determine the height and width
# of the predetermined elements. Then the overall height and width of the
# output PNG are calculated based on what is needed to give the rendered
# tiles the desired size.