Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Bresler abresler

View GitHub Profile
@abresler
abresler / README.md
Created Mar 2, 2016 — forked from timelyportfolio/README.md
nesting and summarizing in R and d3.js
View README.md

Built with blockbuilder.org

Nesting and summarizing data is a very common task for data analysis. I thought it would be nice to view parallel ways of nesting and summarizing with both

  • R | tidyr and dplyr
  • JavaScript | d3.js ...v4 for fun

To avoid context switching, I'll take advantage of the R package V8. If you are an R user, then these d3.js gists might be helpful d3 nest examples and Mister Nester.

@abresler
abresler / diagrammer-bball-vis.R
Last active Dec 18, 2015
Simple visualization of NBA player movements using the DiagrammeR R package
View diagrammer-bball-vis.R
library(DiagrammeR)
library(magrittr)
library(visNetwork)
moments <-
'https://gist.githubusercontent.com/rich-iannone/9c4e50cd5d811b841349/raw/65bc97ddac2f9e52a4252fcf2060007fe1afeb7d/moment.csv' %>%
read_csv()
# Generate the court
court <-
@abresler
abresler / world-cities-diagrammer.R
Created Oct 5, 2015 — forked from rich-iannone/world-cities-diagrammer.R
Demonstration code for plotting a graph of world cities along with country borders with the DiagrammeR R package.
View world-cities-diagrammer.R
# Installation
#install.packages("devtools")
devtools::install_github("rich-iannone/DiagrammeR")
library(DiagrammeR)
# Create a graph of border coordinates
country_graph <- country_graph()
# Read in a CSV with location and population data for cities all over the world
@abresler
abresler / neuralnetR.R
Created Sep 24, 2015 — forked from mick001/neuralnetR.R
A neural network exaple in R. Full article at:
View neuralnetR.R
# Set a seed
set.seed(500)
library(MASS)
data <- Boston
# Check that no data is missing
apply(data,2,function(x) sum(is.na(x)))
# Train-test random splitting for linear model
View Readme.md

Although very handy and useful, I think most new R developers do not even know that tables exist. They are a little tricky to use, but they offer some nice functionality. These tables become even more useful when we can visualize them as networks. This little bit of code is a rough first attempt at converting tables to network nodes and edges.

live example

View base_r_plotting_tutorial_koontz_d-rug.r
### Title: Back to basics: High quality plots using base R graphics
### An interactive tutorial for the Davis R Users Group meeting on April 24, 2015
###
### Date created: 20150418
### Last updated: 20150423
###
### Author: Michael Koontz
### Email: mikoontz@gmail.com
### Twitter: @michaeljkoontz
###
View leafletMapWithLegend.R
#devtools::install_github("rstudio/leaflet", ref="feature/color-legend")
library(leaflet)
library(RColorBrewer)
set.seed(100)
pdf <- data.frame(Latitude = runif(100, -90,90), Longitude = runif(100, -180,180))
#make a property with colors
pdf$Study <- rep(1:10,10)
#need to create a pal using colorbin
View randomized_undirected_graph.R
# Get the latest version of 'DiagrammeR'
install_github("rich-iannone/DiagrammeR")
# Create a 'nodes' data frame
nodes <- sample(1:100, 100, replace = FALSE)
style <- rep("filled", 100)
fillcolor <- c(rep("turquoise", 20), rep("pink", 20),
rep("ochre", 20), rep("gray40", 20),
View dogs.R
# Reading in 'dogs.csv'
# Created by Alex Bresler, available at:
# https://github.com/abresler/abresler.github.io/blob/master/blog/2015/february/exploring_agility_show/data/dogs.csv
dogs <- read.csv("dogs.csv", header = TRUE, stringsAsFactors = FALSE)
# Setting a numeric id
node_id <- 1:nrow(dogs)
# Getting unique values for the 'breed' column
unique_node_2 <- unique(dogs$breed)
View pagerank.R
## Analyze R packages for popularity, using pagerank algorithm
# Inspired by Antonio Piccolboni, http://piccolboni.info/2012/05/essential-r-packages.html
library(miniCRAN)
library(igraph)
library(magrittr)
# Download matrix of available packages at specific date ------------------