Skip to content

Instantly share code, notes, and snippets.

View epijim's full-sized avatar

James Black epijim

View GitHub Profile
@epijim
epijim / scrape.r
Last active December 27, 2015 04:09
Scrape google scholar. Need to edit the links at the bottom to the persons google scholar page.
getPckg <- function(pckg) install.packages(pckg, repos = "http://cran.r-project.org")
pckg = try(require(wordcloud))
if(!pckg) {
cat("Installing 'wordcloud' from CRAN\n")
getPckg("wordcloud")
require("wordcloud")
}
pckg = try(require(tm))
if(!pckg) {
@epijim
epijim / beanplot.r
Last active December 27, 2015 06:29
Bean plot in R
library("beanplot")
#To make it do the split (male/female in my plot), I set a variable up as "MainGrouping" then
# a space followed by BinaryGrouping encoded as a numeric value (i.e. 1 or 2).
beanplot(ContinuousVariable ~ MainGrouping_BinaryGrouping, data = DATA, what=c(1,1,1,0), log="",
ylab = "Continous variable label", side = "both",
border = NA, beanlinewd = 0.5, overallline = "median",
col = list( "brown2", "cadetblue3"))
legend("topright", fill = c("brown2", "cadetblue3"), c("Binary 1", "Binary 2"))
@epijim
epijim / collegewealth.coffee
Created November 5, 2013 12:50
D3.js bubble plot see vlandham/vlandham.github.com for source.
class BubbleChart
constructor: (data) ->
@data = data
@width = 940
@height = 600
# locations the nodes will move towards
# depending on which view is currently being
# used
<!DOCTYPE html>
<meta charset="utf-8">
<style>
svg {
font: 10px sans-serif;
}
.axis path {
display: none;
@epijim
epijim / parsets.r
Last active December 27, 2015 22:09
Parallel Sets. Based off a comment by Aaron Rendahl on CrossValidated.
parallelset <- function(..., freq, col="gray", border=0, layer,
alpha=0.5, gap.width=0.05) {
p <- data.frame(..., freq, col, border, alpha, stringsAsFactors=FALSE)
n <- nrow(p)
if(missing(layer)) { layer <- 1:n }
p$layer <- layer
np <- ncol(p) - 5
d <- p[ , 1:np, drop=FALSE]
p <- p[ , -c(1:np), drop=FALSE]
p$freq <- with(p, freq/sum(freq))
@epijim
epijim / bubbletable.r
Last active December 28, 2015 01:28
bubble tables
# ggplot2 base layer
g <- ggplot(table)
# Bubble plots - edit limits and seq based on your data
(g + geom_point(aes(x = XAxis, y = YAxis, size = Percent, colour = total),shape=16, alpha=0.80) +
scale_colour_gradient(limits = c(0, 1400), low="blue", high="red", breaks= seq(0, 1400, by = 200)) +
scale_x_continuous(breaks = 1:4, labels=c("Category1", "Category2", "Category3","Category4")) +
scale_y_continuous(trans = "reverse") + coord_fixed(ratio=0.2)
)
\documentclass[12pt]{article}
\usepackage{sparklines} % makes inline curves
\begin{document}
Ten-year modelled CVD risk was 27.3 (SD 13.9, histogram
\begin{sparkline}{4} % start first sparkline
\sparkspike .083 .69 % first is x spacing, second is height
\sparkspike .25 .97
@epijim
epijim / mapping_cam.r
Last active December 29, 2015 17:39
Mapping Cambridge
library(ggmap)
getLineColor <- function(val) {
#pal <- colorRampPalette(c("#333333", "#ffffff", "#b5310c"))
pal <- colorRampPalette(c("#ffffff", "red"))
colors <- pal(80)
val.log <- log(val)
if (val > 50) {
col <- colors[80]
@epijim
epijim / load_CamCrimeData.r
Last active December 30, 2015 08:39
load in data from data.police.uk
setwd("Directoy where the data is saved")
library(plyr) # used to read in csvs
library(psych) # has the describe function
################
# import data #
################
# Data is in monthly CSV's, so loop over them pulling in data
@epijim
epijim / mapit.r
Created December 5, 2013 12:38
mapping the police data
theme_bare <- theme(axis.line = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
legend.position = "none")
cambridge <- get_map(location="Cambridge, UK", zoom=13, color="bw", source="osm")