This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: http://stackoverflow.com/a/9314880 | |
color.bar <- function(lut, min, max=-min, nticks=11, ticks=seq(min, max, len=nticks), title='') { | |
scale = (length(lut))/(max-min) | |
# dev.new(width=1.75, height=5) | |
plot(c(0,10), c(min,max), type='n', bty='n', xaxt='n', xlab='', yaxt='n', ylab='', main=title) | |
axis(2, round(ticks, 2), las=1) | |
for (i in 1:(length(lut))) { | |
y = (i-1)/scale + min | |
rect(0,y,10,y+1/scale, col=lut[i], border=NA) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Split a data frame into k subsets | |
# | |
# Returns a list of subsetted data frames of equal (or as close to equal as | |
# possible) size. If the data frame cannot be split equally by k, then the | |
# remainder will be adding to the last k'th subset. User can also request | |
# to put the remainder in an additional k+1 subset. | |
# | |
# This is basically a wrapper around split(), but helps calculate the remainder, | |
# if necessary. | |
split_k <- function(x, k, remainder_as_additional = FALSE) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
from six import iteritems | |
import sys | |
import os | |
import os.path | |
import re | |
import argparse | |
import pandas as pd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Backup R Markdown authored HTML files to a "notebook" sub-directory and add | |
# a timestamp to the HTML file | |
# | |
# e.g. | |
# R_analysis.html -> notebook/R_analysis.2015-02-12.html | |
# | |
# If file is version controlled, then a short commit hash is also added. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a color bar and breaks that center at a specific value | |
# Source: https://stackoverflow.com/a/10986203 | |
colorbar <- function(min, max, threshold=0, palette="RdBu", palette_length=15) { | |
pal <- rev(brewer.pal(9, palette)) | |
# Get all possible breaks | |
my_breaks <- seq(min, max, length.out=palette_length) | |
# Get number of breaks above threshold and below threshold | |
above <- length(which(my_breaks > threshold)) |
OlderNewer