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 / 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 / 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 / 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 / diagrammer-fixed-nodes-visnetwork.R
Last active October 2, 2015 03:34
Fixed nodes (with specified positions) in DiagrammeR
# Installation
#install.packages("devtools")
devtools::install_github("rich-iannone/DiagrammeR")
library(DiagrammeR)
# Create and render an empty graph
empty_graph <- create_graph()
render_graph(empty_graph, output = "visNetwork")
@rich-iannone
rich-iannone / diagrammer-left-to-right.R
Last active November 5, 2015 18:14
DiagrammeR Graphviz graph moving left to right (`rankdir`!)
devtools::install_github("rich-iannone/DiagrammeR")
library(DiagrammeR)
library(magrittr)
# Create a graph
graph <-
create_graph() %>%
set_global_graph_attr("graph", "rankdir", "LR") %>%
add_node("A") %>% add_node("B") %>% add_node("C") %>%
add_node("D") %>% add_node("E") %>% add_node("F") %>%
@rich-iannone
rich-iannone / iris_plot_DiagrammeR.R
Last active February 11, 2016 01:36
How to plot some Iris data with DiagrammeR and export as a PDF or PNG.
devtools::install_github("rich-iannone/DiagrammeR")
library(DiagrammeR)
library(DiagrammeRsvg)
library(magrittr)
# Create three groups (Setosa, Versicolor, and Virginica)
# of x,y datapoints for petal length (x) and petal width (y)
setosa <-
create_xy_pts(
series_label = "Setosa",
@rich-iannone
rich-iannone / sp500_diagrammer.R
Last active February 28, 2016 08:38
Time series graph of S&P 500 data going back to 1950. Uses DiagrammeR for R.
devtools::install_github("rich-iannone/DiagrammeR")
library(DiagrammeR)
library(DiagrammeRsvg)
library(magrittr)
# Read in the data
sp500 <- read.csv(system.file("examples/sp500.csv",
package = "DiagrammeR"),
stringsAsFactors = FALSE)
@rich-iannone
rich-iannone / yr_daily_rainfall_2015.R
Last active February 28, 2016 09:12
Using several R packages (stationaRy, DiagrammeR, DiagrammeRsvg, magrittr, and dplyr), you can create a time-series plot of weather-related things. Here, I plotted daily rainfall during 2015.
# Load in several packages
devtools::install_github("rich-iannone/DiagrammeR")
library(DiagrammeR)
library(DiagrammeRsvg)
library(magrittr)
library(stationaRy)
library(dplyr)
# Get the daily rainfall values (in mm) during 2015 at
# the Vancouver Internation Airport (YVR)
@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 / 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']