Skip to content

Instantly share code, notes, and snippets.

@dill
dill / contour_experiment.R
Created July 16, 2018 20:57
silly experiment with contours
###
n <- 200
add_layer <- function(coords=data.frame(x=0, y=0), layer=0){
so_rad <- seq(0, 2*pi-0.1, len=n)
if(layer==0){
lens0 <- 0.1*runif(1, 0.1, 1)
@dill
dill / figure-captions.R
Created April 14, 2018 12:31
knitr captions in HTML
## this code makes figure captions work in HTML output
# adapted from http://gforge.se/2014/01/fast-track-publishing-using-knitr-part-iii/
library(knitr)
options(figure_counter = TRUE)
# Evaluate the figure caption after the chunk,
# sometimes you want to calculate stuff inside the
# chunk that you want to include in the caption and
# it is therefore useful to evaluate it afterwards.
@dill
dill / new-mac-settings.sh
Last active February 28, 2019 16:31
Setup a new Mac 💻
#!/usr/bin/env bash
# David L Miller
# updated 28 February 2019
# taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# https://twitter.com/chadwhitaker/status/1004441991415922688
# https://www.idownloadblog.com/2014/08/03/how-to-remove-the-shadow-window-screenshots-on-mac-os-x/
# and elsewhere
@dill
dill / ebird_sp_disc.R
Created January 9, 2018 09:37
make an eBird species discovery curve
### species discovery curve from eBird
library(lubridate)
# life list
life <- read.csv("ebird_world_life_list.csv")
life$date <- lubridate::dmy(as.character(life$Date))
#sort
life <- life[order(life$date),]
@dill
dill / howfar2017.R
Last active January 5, 2018 13:18
How far did I travel in 2017?
# how far did I go in 2017?
# read in the list of places I went to
txt <- readLines("howfar2017.txt")
# decode the place names to lat/long
library(ggmap)
gg <- geocode(txt, source="dsk")
@dill
dill / health.R
Created January 5, 2018 12:53
Do a quick analysis of the Health data collected by iPhones
library(XML)
# pull in the xml file
# can export this from the iPhone and e-mail it to youself
xx <- xmlParse("export.xml")
xx <- xmlToList(xx)
# now do some data mudging
library(plyr)
@dill
dill / hi_len.R
Created May 22, 2017 19:02
Uncertainty estimation and plotting in dsm
# for LJT
# this wasn't as simple as I thought, it was the summary() method that does the smart thing
# so there is a bit of split() nonsense to deal with...
library(Distance)
library(dsm)
library(ggplot2)
@dill
dill / gridstuff.R
Last active April 7, 2017 00:59
grids in the right place
# make a boundary
library(mapdata)
library(maptools)
library(rgeos)
library(ggplot2)
library(sp)
# build the coastline
coastline <- map("world", c("USA", "Canada"), plot=FALSE)
@dill
dill / better_check.R
Last active September 14, 2021 17:09
Combined deviance and quantile residuals check plots for GAMs
library(gridBase)
library(grid)
library(mgcv)
library(statmod)
## nicer version of gam.check/rqgam.chack
# - deviance residuals for the Q-Q and histogram
# - RQR for resids vs linear pred
# - response vs fitted
# hist.p gives the quantiles of the residuals to show
better_check <- function(b, k.sample = 5000, k.rep = 200, rep = 0, level = 0.9,
@dill
dill / the_empire_strikes_back.R
Last active August 26, 2016 03:42
End Imperialism! (in terms of units of length, at least) 📏 👍
# try to understand measurements from the past...
# possible input types:
# - 5
# - 5'
# - 5'5
# - 5'7 1/2
# - 5'7\"
# - 5'8.5
# - 5'61/2\"