Skip to content

Instantly share code, notes, and snippets.

View randyzwitch's full-sized avatar

Randy Zwitch randyzwitch

View GitHub Profile
@randyzwitch
randyzwitch / wordpress-base-r.R
Created July 21, 2014 18:01
Re-creating WordPress chart using Base R graphics
#Load Data
#Make sure months stay ordered - first time I ever wanted a factor!
#Label x-axis with every fifth label...need to use character(0) in base graphics, not " "?
visits_visitors <- read.csv("visits_visitors.csv")
visits_visitors$Month <- factor(visits_visitors$Month, levels = visits_visitors$Month, ordered = TRUE)
visits_visitors$Month_ <- ifelse(as.numeric(row.names(visits_visitors)) %% 5 == 0, as.character(visits_visitors$Month), character(0))
#Set up plot space for plot & add horizontal lines
barplot(visits_visitors$Views, ylim = c(0,10000), las=1, border = NA, col.axis = "darkgray", tick = FALSE)
abline(h=seq(2000,10000, 2000), col='lightgray')
@randyzwitch
randyzwitch / VennEuler.ipynb
Last active July 4, 2016 13:58
VennEuler.jl example
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@randyzwitch
randyzwitch / venneuler-circle.jl
Created August 29, 2014 19:09
VennEuler Circle example
#Circles
eo = make_euler_object(labels, data, EulerSpec()) # circles, for now
(minf,minx,ret) = optimize(eo, random_state(eo), ftol=-1, xtol=0.0025, maxtime=120, pop=1000)
println("got $minf at $minx (returned $ret)")
render("/home/rzwitch/Desktop/kd.svg", eo, minx)
@randyzwitch
randyzwitch / venneuler-rect.jl
Created August 29, 2014 19:11
VennEuler Rectangle example
# Rectangles
eo = make_euler_object(labels, data, [EulerSpec(:rectangle), EulerSpec(:rectangle, [.5, .5, .4], [0, 0, 0]),
EulerSpec(:rectangle)],
sizesum=.3)
(minf,minx,ret) = optimize_iteratively(eo, random_state(eo), ftol=-1, xtol=0.0025, maxtime=5, pop=100)
println("phase 1: got $minf at $minx (returned $ret)")
(minf,minx,ret) = optimize(eo, minx, ftol=-1, xtol=0.001, maxtime=30, pop=100)
println("phase 2: got $minf at $minx (returned $ret)")
@randyzwitch
randyzwitch / rsitecatalyst-queuepathing.R
Created September 7, 2014 00:24
QueuePathing RSiteCatalyst example
library("RSiteCatalyst")
library("d3Network")
#### Authentication
SCAuth("username", "secret")
#### Get Pathing data using ::anything:: wildcards
# Results are limited by the API to 50000
pathpattern <- c("::anything::", "::anything::")
@randyzwitch
randyzwitch / simpleNetwork-1.R
Created September 7, 2014 00:31
Simple Graph of RSiteCatalyst pathing data
#Optional step: Cleaning my pagename URLs to remove to domain for graph clarity
queue_pathing_pages$step.1 <- sub("http://randyzwitch.com/","",
queue_pathing_pages$step.1, ignore.case = TRUE)
queue_pathing_pages$step.2 <- sub("http://randyzwitch.com/","",
queue_pathing_pages$step.2, ignore.case = TRUE)
#### Remove Enter and Exit site values
#This information is important for analysis, but not related to website structure
graph_links <- subset(queue_pathing_pages, step.1 != "Entered Site" & step.2 != "Exited Site")
@randyzwitch
randyzwitch / simpleNetwork-2.R
Created September 7, 2014 15:07
Pruned Simple Graph of RSiteCatalyst pathing data
#### Second pass: thin the spaghetti blob!
#Require path to happen more than some number of times (count > x)
#What constitutes "low volume" will depend on your level of traffic
simpleoutput2 = "C:/Users/rzwitc200/Desktop/simpleoutput2.html"
d3SimpleNetwork(subset(graph_links, count > 5), Source = "step.1", Target = "step.2", height = 600,
width = 750, fontsize = 12, linkDistance = 50, charge = -100,
linkColour = "#666", nodeColour = "#3182bd",
nodeClickColour = "#E34A33", textColour = "#3182bd", opacity = 0.6,
standAlone = TRUE, file = simpleoutput2)
@randyzwitch
randyzwitch / force-directed-d3-rsitecatalyst.R
Created September 8, 2014 00:28
Force-directed network with RSiteCatalyst
#### Force directed network
#Limit to more than 5 occurence like in simple network
fd_graph_links <- subset(graph_links, count > 5)
#Get unique values of page name to create nodes df
#Create an index value, starting at 0
fd_nodes <- as.data.frame(unique(c(fd_graph_links$step.1, fd_graph_links$step.2)))
names(fd_nodes) <- "name"
fd_nodes$nodevalue <- as.numeric(row.names(fd_nodes)) - 1
@randyzwitch
randyzwitch / seaborn-stacked-bar.py
Created September 8, 2014 21:08
Python Seaborn Stacked Bar Chart
import pandas as pd
from matplotlib import pyplot as plt
import matplotlib as mpl
import seaborn as sns
%matplotlib inline
#Read in data & create total column
stacked_bar_data = pd.read_csv("C:\stacked_bar.csv")
stacked_bar_data["total"] = stacked_bar_data.Series1 + stacked_bar_data.Series2
@randyzwitch
randyzwitch / rsitecatalyst-sankey-one-page.R
Created September 10, 2014 20:42
RSiteCatalyst Sankey Diagram - Single Page to Multiple Pages
library("RSiteCatalyst")
library("d3Network")
#### Authentication
SCAuth("key", "secret")
#### Get Pathing data: Single page, then ::anything:: pattern
pathpattern <- c("http://randyzwitch.com/big-data-hadoop-amazon-ec2-cloudera-part-1", "::anything::")
next_page <- QueuePathing("zwitchdev",
"2014-01-01",