Skip to content

Instantly share code, notes, and snippets.

View scipionesarlo's full-sized avatar

Scipione Sarlo scipionesarlo

View GitHub Profile
@scipionesarlo
scipionesarlo / gist:344b2766f955c2bb979a7580c3aa325d
Created September 6, 2017 23:31 — forked from johanlaidlaw/gist:1596626
Scraper for transfermarkt
<?php
include_once('../simple_html_dom.php');
function scraping($url) {
// create HTML DOM
$html = file_get_html($url);
// Find the table that has class="tabelle_spieler" in the source code
// There are two of these tables and we want the second one therefor 1 (index start by 0)
@scipionesarlo
scipionesarlo / 2nd_axis.r
Created August 3, 2017 15:39 — forked from johnDorian/2nd_axis.r
Function to plot secondary axis in ggplot2
library(ggplot2)
library(gtable)
library(grid)
library(ggthemes)
# extract gtable
ggplot_second_axis <- function(p1, p2){
p2 <- p2 + theme() %+replace%
@scipionesarlo
scipionesarlo / diverge0.R
Created February 6, 2017 16:31 — forked from johnbaums/diverge0.R
Plot a rasterVis::levelplot with a colour ramp diverging around zero
diverge0 <- function(p, ramp) {
# p: a trellis object resulting from rasterVis::levelplot
# ramp: the name of an RColorBrewer palette (as character), a character
# vector of colour names to interpolate, or a colorRampPalette.
require(RColorBrewer)
require(rasterVis)
if(length(ramp)==1 && is.character(ramp) && ramp %in%
row.names(brewer.pal.info)) {
ramp <- suppressWarnings(colorRampPalette(brewer.pal(11, ramp)))
} else if(length(ramp) > 1 && is.character(ramp) && all(ramp %in% colors())) {
@scipionesarlo
scipionesarlo / raster_scatter.R
Created December 9, 2015 15:24 — forked from dsparks/raster_scatter.R
Drawing a scatter plot of raster images
# Drawing a scatter plot of raster images
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("png", "devtools", "MASS", "RCurl")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Some helper functions, lineFinder and makeTable
source_gist("818983")
source_gist("818986")
@scipionesarlo
scipionesarlo / code.R
Last active September 6, 2015 16:14 — forked from timelyportfolio/code.R
rCharts Implements d3.js Sankey Plugin
require(rCharts)
require(rjson)
#get source from original example
#this is a JSON, so will need to translate
#this is complicated and unnecessary but feel I need to replicate
#for completeness
#expect most data to come straight from R
#in form of source, target, value
face suit value
king spades 13
queen spades 12
jack spades 11
ten spades 10
nine spades 9
eight spades 8
seven spades 7
six spades 6
five spades 5