Skip to content

Instantly share code, notes, and snippets.

View epijim's full-sized avatar

James Black epijim

View GitHub Profile
@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)
)
@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))
<!DOCTYPE html>
<meta charset="utf-8">
<style>
svg {
font: 10px sans-serif;
}
.axis path {
display: none;
@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
@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 / 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 / stacked_histogram.r
Created October 1, 2013 13:58
stacked histogram
plot using ggplot2
require(ggplot2)
#data
set.seed(1233)
data1 <- data.frame(pop =c(rep("A x B", 200), rep("A x C", 200), rep("B x C", 200) ) , var1 = c(rnorm(1000, 90,10), rnorm(1000, 50, 10), rnorm(1000, 20, 30)))
qplot( var1, data = data1, geom = "histogram" , group = pop, fill = pop, alpha=.3) + theme_bw( )
@epijim
epijim / histwithboxplot.r
Created October 1, 2013 13:43
a histograph with a bar chart overlaid
# data
set.seed(4566)
data <- rnorm(100)
# Added to the plot:
par(mar=c(3.1, 3.1, 1.1, 2.1))
hist(data,xlim=c(-4,4), col = "pink")
boxplot(data, horizontal=TRUE, outline=TRUE, ylim=c(-4,4), frame=F, col = "green1", add = TRUE)
@epijim
epijim / swarmplot.r
Created October 1, 2013 13:26
swarmplot, visualise continuous distribution by a catergorical stratification variable.
# data
set.seed(1234)
bimodal <- c(rnorm(250, -2, 0.6), rnorm(250, 2, 0.6))
uniform <- runif(500, -4, 4)
normal <- rnorm(500, 0, 1.5)
dataf <- data.frame (group = rep(c("bimodal","uniform", "normal"), each = 500), xv = c(bimodal, uniform, normal), cg = rep( c("A","B"), 750))
require(beeswarm)
# hexagon
@epijim
epijim / Proportional twoway (or more, in a mosiac plot).r
Last active December 23, 2015 03:39
Simple example - a two way table of categorical variables, with size proportional to number
library(vcd)
# create a matrix with two categorical variables.
VECTOR <- xtabs(~ Var1 + Var2, data = Dataframe)
# create mosiac
mosaic(VECTOR, gp = shading_max, split_vertical = TRUE)