Skip to content

Instantly share code, notes, and snippets.

View jalapic's full-sized avatar

James Curley jalapic

View GitHub Profile
@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")),
# function to do a dodged half-boxplot and jittered points next to each other
#
# data_in should be a data frame
# factor_col should be a bare column name (not a string)
# although it will work if that column is factor or a character type
# numeric_col is the y axis continuous variable
# offset is the width of the boxplots and jittered point cloud
#
# the basic approach is to draw a boxplot without the tails
# (e.g. only the interquartile range) and then use segments to add the
@bayesball
bayesball / broom_career_trajectory.R
Created July 1, 2016 00:40
Illustrating broom package using career trajectory of home run rates
# read in Lahman batting and master files
# can also use Lahman package -- data is only through 2014 season
Batting <- read.csv("~/OneDriveBusiness/lahman-csv_2015-01-24/Batting.csv")
Master <- read.csv("~/OneDriveBusiness/lahman-csv_2015-01-24/Master.csv")
# find players with at least 500 career homes (through 2015)
library(dplyr)
from __future__ import print_function
import copy
class permutor:
def __init__(self, infile='curley_seq.txt', max_entries=-1):
self.indata = self.read_infile(infile)
if max_entries>0:
self.indata = self.indata[0:max_entries]
# devtools::install_github('jalapic/engsoccerdata')
library(engsoccerdata)
library(dplyr)
library(plotly)
library(htmlwidgets)
england$Date <- as.Date(england$Date, format = "%Y-%m-%d")
#Get Data into Format Needed
df<-rbind(
library(ggplot2) # devtools::install_github("hadley/ggplot2") or subtitles won't work
library(tidyr)
library(dplyr)
library(readr)
library(scales)
URL <- "https://static01.nyt.com/newsgraphics/2016/04/21/undervote/ad8bd3e44231c1091e75621b9f27fe31d116999f/data.tsv"
fil <- "nytimes_vote.tsv"
if (!file.exists(fil)) download.file(URL, fil)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 34 columns, instead of 5. in line 4.
name.table,id.season,is.offense,name.player,team,id.player,jersey,id.position,id.team,slug.team,city.team,gp,possesions,pct.play_type,pts,fga,fgm,ppp,ppp.worse,ppp.better,possesions.per_game,pts.per_game,fga.per_game,fgm.per_game,fg.miss.per_game,rank,pct.fg,pct.efg,pct.ft_achieved,pct.to,pct.shooting_foul,pct.and_1,pct.scored,stem.table
Post-Up,2015-16,TRUE,Paul Millsap,Atlanta Hawks,200794,4,F,1610612737,ATL,Atlanta,4,13,19.69700050354,20,8,7,1.53846001625061,25,0,3.25,5,2,1.75,0.25,1,87.5,87.5,30.7692307692308,15.3846153846154,30.7692307692308,7.69230769230769,76.9230769230769,Postup
Post-Up,2015-16,TRUE,Al Horford,Atlanta Hawks,201143,15,F-C,1610612737,ATL,Atlanta,4,11,15.0684995651245,12,8,6,1.09090995788574,17,7,2.75,3,2,1.5,0.5,2,75,75,0,27.2727272727273,0,0,54.5454545454545,Postup
Post-Up,2015-16,FALSE,Kent Bazemore,Atlanta Hawks,203145,24,G,1610612737,ATL,Atlanta,4,11,22.917,7,7,1,0.636,5,4,2.75,1.75,1.75,0.25,1.5,6,14.286,14.286,27.273,9.091,27.273,0,36.364,Postup
Post-Up,2015-16,FALSE,Al Horford,A
library(SmarterPoland)
library(riverplot)
library(RColorBrewer)
library(graphics)
library(reshape2)
library(plyr)
library(stringr)
library(countrycode)
# DOWNLOAD THE DATA