Skip to content

Instantly share code, notes, and snippets.

@johnburnmurdoch
johnburnmurdoch / .block
Last active December 20, 2022 17:31
Watercolour affect using HTML5 canvas
license: mit
height: 620
scrolling: no
border: no
@johnburnmurdoch
johnburnmurdoch / .block
Last active February 26, 2018 16:46
Generative line intersections
license: mit
scrolling: no
border: no
@johnburnmurdoch
johnburnmurdoch / index.html
Last active March 2, 2018 00:15
Three-way interactive scatter, showing where points lie on three axes
<!doctype html>
<html lang="">
<head>
<meta charset="utf-8">
<title>Three-way scatter</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type='text/javascript' src='https://unpkg.com/d3'></script>
<script type='text/javascript' src='https://unpkg.com/d3-selection-multi'></script>
@johnburnmurdoch
johnburnmurdoch / main.R
Created March 1, 2018 19:15
Vectorising for loops to save time in R
needs(tidyverse, magrittr, jsonlite, scales)
loopTimer <- function(rows){
col1 <- runif (rows, 0, 2)
col2 <- rnorm (rows, 0, 2)
col3 <- rpois (rows, 3)
col4 <- rchisq (rows, 2)
df <- data.frame (col1, col2, col3, col4)
@johnburnmurdoch
johnburnmurdoch / .block
Last active March 25, 2023 06:13
Spirograph effect in HTML canvas
license: mit
height: 545
scrolling: no
border: no
@johnburnmurdoch
johnburnmurdoch / data.csv
Created April 3, 2018 07:35
Mapping population change across US counties, highlighting the "doughnut" ring effect in many growing metro areas
We can't make this file beautiful and searchable because it's too large.
fips,stname,ctyname,fullname,year,estimate
01001,Alabama,Autauga County,"Autauga County, Alabama",2000,44021
01001,Alabama,Autauga County,"Autauga County, Alabama",2001,44889
01001,Alabama,Autauga County,"Autauga County, Alabama",2002,45909
01001,Alabama,Autauga County,"Autauga County, Alabama",2003,46800
01001,Alabama,Autauga County,"Autauga County, Alabama",2004,48366
01001,Alabama,Autauga County,"Autauga County, Alabama",2005,49676
01001,Alabama,Autauga County,"Autauga County, Alabama",2006,51328
01001,Alabama,Autauga County,"Autauga County, Alabama",2007,52405
01001,Alabama,Autauga County,"Autauga County, Alabama",2008,53277
@johnburnmurdoch
johnburnmurdoch / index.html
Last active October 27, 2019 19:39
Javascript/canvas city generator
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<title>Canvas City</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<canvas></canvas>
@johnburnmurdoch
johnburnmurdoch / index.html
Created October 24, 2018 13:24
d3: translating text and rotating in-situ
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://unpkg.com/d3@5"></script>
<script src="https://unpkg.com/d3-selection-multi"></script>
<style>
* {
margin: 0;
padding: 0;
border: 0;
# Data is the UN's Medium-variant population projections, available at https://population.un.org/wpp/
data %>%
filter(Sex != "Both" & A3 %in% c("GBR", "RUS", "IND", "CHN", "RWA", "GRC") & Year %in% 2018:2060) %>%
as.tibble %>%
mutate(
group = paste0(Year, Sex), AgeGrp = as.numeric(AgeGrp),
Location = Location %>% gsub("n Federation","",.)
) %>%
ggplot(aes(AgeGrp, Value, col=Sex, group=group)) +
@johnburnmurdoch
johnburnmurdoch / mourinho_clubelo.R
Created December 18, 2018 17:57
Scripts for downloading and visualising data from clubelo.com showing José Mourinho’s third season problem. A hand-finished version of this chart appears in this Financial Times story: https://www.ft.com/content/56acdd82-02d2-11e9-99df-6183d3002ee1
needs(tidyverse, magrittr, scales)
jose.porto <- read_csv("http://api.clubelo.com/porto")
jose.chelsea <- read_csv("http://api.clubelo.com/chelsea")
jose.inter <- read_csv("http://api.clubelo.com/inter")
jose.real <- read_csv("http://api.clubelo.com/realmadrid")
jose.mufc <- read_csv("http://api.clubelo.com/manunited")
jose.all <- bind_rows(
jose.porto %>% filter(From >= as.Date("2002-01-22") & To <= as.Date("2004-06-30")),