Skip to content

Instantly share code, notes, and snippets.

View JoFrhwld's full-sized avatar

Josef Fruehwald JoFrhwld

View GitHub Profile
@JoFrhwld
JoFrhwld / ling-plot.Rnw
Created April 14, 2012 20:49
A knitr source file for including linguistic notation as graphical elements in ggplot2
\documentclass{beamer}
\usetheme{Singapore}
\usepackage{tipa}
%% Make the r-code small
\ifdefined\knitrout
\renewenvironment{knitrout}{\begin{footnotesize}}{\end{footnotesize}}
\else
\fi
@JoFrhwld
JoFrhwld / revlog.R
Created March 31, 2012 17:32
ggplot2 reverse log coordinate transform
## ggplot2 and mgcv for the plot
library(ggplot2)
library(mgcv)
## scales packages to define revlog
library(scales)
revlog_trans <- function(base = exp(1)){
## Define the desired transformation.
trans <- function(x){
@JoFrhwld
JoFrhwld / phila.schools.R
Created March 7, 2012 20:33
Mapping Philadelphia Highschools
library(rgdal) #This may be a pain to get installed. The OGR functions come from it.
## install gdal, available here: http://www.gdal.org/
## install proj.4, available here: http://trac.osgeo.org/proj/
## For some reason, R wasn't expecting for libproj to be installed where it was,
## so I had to tell it to look at /usr/local/bin
library(ggplot2)
library(reshape2)
library(plyr)
gpclibPermit()
@JoFrhwld
JoFrhwld / phila.schools.R
Created March 7, 2012 20:33
Mapping Philadelphia Highschools
library(rgdal) #This may be a pain to get installed. The OGR functions come from it.
## install gdal, available here: http://www.gdal.org/
## install proj.4, available here: http://trac.osgeo.org/proj/
## For some reason, R wasn't expecting for libproj to be installed where it was,
## so I had to tell it to look at /usr/local/bin
library(ggplot2)
library(reshape2)
library(plyr)
gpclibPermit()
@JoFrhwld
JoFrhwld / philly.motion.R
Created October 31, 2011 22:10
Making a google motion chart
##########
## Block 1: Preparing the data
library(plyr)
library(reshape)
## Create a Subsystem Column
all_philly$Subsystem <- all_philly$VClass
levels(all_philly$Subsystem) <- c("Vhr", "Vw", "V", "misc", "Vh", "Vh", "Vhr", "Vw", "Vy",
"Vy", "V", "Vy", "Vy", "Vy", "V", "Vw", "Vy", "Vy", "Vhr",
@JoFrhwld
JoFrhwld / clip.border.R
Created May 24, 2010 18:22
Maps Functions
clip.border <- function(deldir.obj, border){
## deldir.obj = output of deldir::deldir
## border = list of borders defined in data frames
## Importantly, with columns called "x" and "y"
require(gpclib)
## bord will be a gpc polygon of all of the regions given to the argument "border"
bord <- as(matrix(ncol = 2), "gpc.poly")
for(i in seq(along = border)){
b <- as(border[[i]], "gpc.poly")
scored_vclass <- function(df,class,vowels, dims = c("F1","F2")){
require(MASS)
df <- df[df[ ,class] %in% vowels, ]
df[ ,class] <- as.character(df[ ,class])
df[,class] <- as.factor(df[,class])
for(i in dims){