Skip to content

Instantly share code, notes, and snippets.

View davidcoallier's full-sized avatar

David Coallier davidcoallier

View GitHub Profile
user created.at pages.visited
julie 2011-11-16 03:31:56 GMT 3
julie 2011-11-16 04:22:33 GMT 5
jack 2011-11-16 07:19:13 GMT 8
jack 2011-11-16 12:39:02 GMT 9
julie 2011-11-17 12:39:02 GMT 3

Mapping the Streets of Ireland With R and ggplot2

Earlier today an interesting article about plotting the streets of france appeared in my feed. What Simon does in his blog post is essentially read OSM street-lines-data for France and displays it in what I find to be a rather traditional and elegant way.

The first thing I immediately though of was: "I'd love to see this for Ireland". As an OSX user, it took a few tricks to get the article replicated for Ireland therefore I've decided to share my notes.

Should you wish to replicate this for your country, here are some notes I've taken.

Get The Data

Load Data With Hmisc

Often times when working with data in R, you find yourself needing to summarise a data.frame by a column, a SELECT SUM(..) or SELECT COUNT(..) in MySQL if you will.

For instance, you may have a lot of page-visits to analyse and you aren't quite certain how to summarise some of that data using R.

Let's consider the following (trivial) dataset:

@davidcoallier
davidcoallier / language-popularity-on-stack-overflow.R
Created March 14, 2013 13:15
Script that looks up and plots the language popularity based on the stack-overflow tag-count.
require(RColorBrewer)
require(ggplot2)
require(scales)
# Thanks to drew conway for this handy function.
get.stack<-function(tok) {
# Must check for XML install, thanks onertipaday!
if (!require(XML)) install.packages('XML')
library(XML)
# Enter a SO tag as character string, and number of tags are returned
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Year Divided Unified D Unified R
1938 10 21 15
1940 15 19 12
1942 9 17 20
1944 10 18 18
1946 8 17 21
1948 15 18 13
1950 15 15 16
1952 8 14 24
1954 16 16 14
@davidcoallier
davidcoallier / peakdet.m
Created September 29, 2012 21:30 — forked from endolith/peakdet.m
Peak detection in Python
function [maxtab, mintab]=peakdet(v, delta, x)
%PEAKDET Detect peaks in a vector
% [MAXTAB, MINTAB] = PEAKDET(V, DELTA) finds the local
% maxima and minima ("peaks") in the vector V.
% MAXTAB and MINTAB consists of two columns. Column 1
% contains indices in V, and column 2 the found values.
%
% With [MAXTAB, MINTAB] = PEAKDET(V, DELTA, X) the indices
% in MAXTAB and MINTAB are replaced with the corresponding
% X-values.
> x <- c(1,3,6,9,12)
> y <- c(1.5,2,7,8,15)
> plot(x,y)
*** caught segfault ***
address 0x0, cause 'memory not mapped'
$ ./sapi/cli/php -r 'print_r([1, 2, 3]);'
Array
(
[0] => 1
[1] => 2
[2] => 3
)
@davidcoallier
davidcoallier / crash-oio-office.pl
Created December 20, 2011 19:33
crash the orchestra network
#!/usr/bin/perl
##############
# udp flood.
##############
use Socket;
use strict;
my $argc = @ARGV + 1;
@davidcoallier
davidcoallier / happybirthdayadatask.adb
Created October 7, 2011 14:58
Happy Birthday Ada Lovelace
--
-- Is there a better way to celebrate ones birthday than
-- generating an Ascii cake and some text-output wishin
-- happy birthday to the person I consider one of the most
-- important person in the history of automated computation.
--
-- Note:
-- Compile with gcc after having installed GNAT (If on OSX)
-- $> gcc -c happybirthdayadatask.adb
-- $> gnatbl -o happybirthday happybirthdayadatask.ali