Skip to content

Instantly share code, notes, and snippets.

View jamestrimble's full-sized avatar

James Trimble jamestrimble

View GitHub Profile
@jamestrimble
jamestrimble / open-paper-pdf.vim
Created January 13, 2017 20:36
Open the saved PDF of a paper by typing Ctrl-P when the cursor is over a reference in a BibTex or LaTeX file
nnoremap <C-P> :!evince ~/Papers/pdf/<cfile>:t.pdf &<CR>
// usage
// node reduce.js worldmap.geojson 3
var fs = require('fs')
var json_string = fs.readFileSync(process.argv[2])
var precision = parseInt(process.argv[3])
console.log('original length: ' + json_string.length)
@jamestrimble
jamestrimble / airports.json
Last active August 29, 2015 13:57
Low Cost Connections
{
"AAL": {
"city": "Aalborg",
"country": "Denmark",
"long_lat": [
"9.849164",
"57.092789"
],
"name": "Aalborg",
"routes": [
@jamestrimble
jamestrimble / Development project experiments
Last active August 29, 2015 13:57
Development project experiments
_
@jamestrimble
jamestrimble / country-topo.json
Last active January 2, 2016 10:59
A not-very-successful attempt at visualising the whisky data from https://www.mathstat.strath.ac.uk/outreach/nessie/nessie_whisky.html
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jamestrimble
jamestrimble / census_data_for_online_map.r
Last active January 17, 2017 19:03
An R script to prepare the data for ukdataexplorer.com/census/ Based on work by Alex Singleton, http://www.alex-singleton.com/2011-census-open-atlas-project/
# Script to create data for http://ukdataexplorer.com/census/
# Author James Trimble, james.trimble at yahoo.co.uk
#
# This code is based on Alex Singleton's work:
# http://rpubs.com/alexsingleton/openatlas
# http://www.alex-singleton.com/2011-census-open-atlas-project/
#
# The script takes around an hour to run. It could be made faster!
# The script requires a lookup table and shapefile from
# https://geoportal.statistics.gov.uk/geoportal/catalog/search/browse/browse.page
# eurostat_r.r should be in the working directory.
# See http://johanneskutsam.blogspot.co.uk/2012/10/eurostat-in-r-in-git.html
library(ggplot2)
library(scales)
source('eurostat_r.r')
 
eu_codes <- c('BE', 'BG', 'CZ', 'DK', 'DE', 'EE', 'IE', 'EL', 'ES',
              'FR', 'HR', 'IT', 'CY', 'LV', 'LT', 'LU', 'HU', 'MT',
@jamestrimble
jamestrimble / eurostat_example.r
Created September 16, 2013 10:01
An example script that plots a chart in ggplot2 using data downloaded from Eurostat.
# This script plots the youth unemployment rate in EU countries.
# Note that there are time series breaks and some values are
# estimated. This is shown in the 'flag' column but not on the chart.
# To get the data, follow this bookmarked link and download the data as csv:
# http://appsso.eurostat.ec.europa.eu/nui/show.do?query=BOOKMARK_DS-055628_QID_605AF573_UID_-3F171EB0&layout=TIME,C,X,0;SEX,L,Y,0;GEO,B,Y,1;S_ADJ,L,Z,0;AGE,L,Z,1;INDICATORS,C,Z,2;&zSelection=DS-055628AGE,Y_LT25;DS-055628INDICATORS,OBS_FLAG;DS-055628S_ADJ,SA;&rankName1=AGE_1_2_-1_2&rankName2=S-ADJ_1_2_-1_2&rankName3=INDICATORS_1_2_-1_2&rankName4=TIME_1_0_0_0&rankName5=SEX_1_2_0_1&rankName6=GEO_1_2_1_1&sortC=ASC_-1_FIRST&rStp=&cStp=&rDCh=&cDCh=&rDM=true&cDM=true&footnes=false&empty=false&wai=false&time_mode=ROLLING&time_most_recent=false&lang=EN&cfo=%23%23%23%2C%23%23%23.%23%23%23
library(ggplot2)
library(scales)
library(zoo)
@jamestrimble
jamestrimble / nomis_api_example.r
Last active December 22, 2015 20:59
Download claimant count data from the Nomis API to R, and plot a chart using ggplot2.
library(ggplot2)
nomis <- read.csv('http://www.nomisweb.co.uk/api/v01/dataset/NM_1_1.data.csv?geography=1941962826...1941962836&date=latestMINUS156,latestMINUS144,latestMINUS132,latestMINUS120,latestMINUS108,latestMINUS96,latestMINUS84,latestMINUS72,latestMINUS60,latestMINUS48,latestMINUS36,latestMINUS24,latestMINUS12,latest&sex=5...7&item=1&measures=20100,20203&select=date_name,geography_name,geography_code,sex_name,item_name,measures_name,obs_value,obs_status_name')
dates <- paste("1", nomis$DATE_NAME)
nomis$date <- as.Date(dates, format <- "%d %B %Y")
cc_rate <- subset(nomis, MEASURES_NAME=='Proportion of resident population aged 16-64 estimates')
# reorder the data
most_recent_cc_rates <- subset(cc_rate, date==max(date) & SEX_NAME=='Total')
order_for_names <- rev(order(most_recent_cc_rates$OBS_VALUE))
@jamestrimble
jamestrimble / ONS_data_to_R.r
Last active December 22, 2015 07:59
An example of downloading time series from the UK Office for National Statistics directly to R
# ONS datasets can be found at
# http://www.ons.gov.uk/ons/datasets-and-tables/index.html
# (Filter out reference tables at the right of the page)
library(reshape2)
library(plyr)
library(ggplot2)
# This is the time-consuming part. To get the maximum use out of your data,
# create a CSV file listing CDIDs (variable codes) and some metadata.