Skip to content

Instantly share code, notes, and snippets.

View rich-iannone's full-sized avatar

Richard Iannone rich-iannone

View GitHub Profile
@rich-iannone
rich-iannone / transition_between_graphs.R
Created April 12, 2015 02:26
Experimental R script to transition between two graph states in DiagrammeR with D3.
require(DiagrammeR)
require(stringr)
# Animation test
nodes <- c("a", "b", "c") # must be named 'nodes' and should have unique values
nodes_df <- data.frame(nodes)
edge_from <- c("a", "a", "b")
@rich-iannone
rich-iannone / us_cities_graph.R
Last active August 29, 2015 14:17
This is a Graphviz diagram that shows major US cities (with population greater than 300,000 people). Uses chromatography.js to provide some color by US state, and, the DiagrammeR R package (https://github.com/rich-iannone/DiagrammeR) to render the graph.
# install.packages("downloader")
# devtools::install_github("rich-iannone/DiagrammeR")
# devtools::install_github("jeroenooms/V8")
library("downloader")
library("DiagrammeR")
library("V8")
# Create a function that uses the 'chromatography' JS library to generate a random
# set of colors from the CIE Lab color space
@rich-iannone
rich-iannone / chromatography.R
Last active August 29, 2015 14:16
R function that loads in chromatography.js, constructs a string of JS code, passes that code for evaluation (using the 'V8' package), and returns a palette of visually different colors.
library(V8)
# Create function to generate palette of visually different colors
hex_palette <- function(no_colors,
hue_range = NULL,
chroma_range = NULL,
lightness_range = NULL){
pal <- function(col, border = "light gray", ...){
n <- length(col)
@rich-iannone
rich-iannone / several-ranks-neato-overlap-true.R
Last active October 1, 2017 14:33
This is an undirected Graphviz graph with 407 nodes amongst several ranks. Graph edges have varying lengths. It is rendered with the 'neato' engine, and, the graph attribute 'overlap' is set to true.
grViz("
graph severalranks {
node [shape = circle, fixedsize = true, fontcolor = '#555555',
fontname = Helvetica, fontsize = 7, style = filled,
fillcolor ='#AAAAAA', color='#555555', width = 0.12,
height = 0.12, nodesep = 0.1]
edge [color = '#AAAAAA']
@rich-iannone
rich-iannone / several-ranks-neato-overlap-false.R
Last active July 12, 2017 06:36
This is an undirected Graphviz graph with 407 nodes amongst several ranks. Graph edges have varying lengths. It is rendered with the 'neato' engine, and, the graph attribute 'overlap' is set to false.
grViz("
graph severalranks {
node [shape = circle, fixedsize = true, fontcolor = '#555555',
fontname = Helvetica, fontsize = 7, style = filled,
fillcolor ='#AAAAAA', color='#555555', width = 0.12,
height = 0.12, nodesep = 0.1]
edge [color = '#AAAAAA']
@rich-iannone
rich-iannone / subset.POSIXct.R
Last active April 8, 2022 08:48
Several examples in R on creating subsets of data via a POSIXct time object.
# Create a simple data frame for testing
df <- data.frame(POSIXtime = seq(as.POSIXct('2013-08-02 12:00'),
as.POSIXct('2013-08-06 05:00'), len = 45),
x = seq(45))
# The Subset Examples
#
# All data on 2013-08-06
sub.1 <- subset(df, format(POSIXtime,'%d')=='06')