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 / 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')
@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']
@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_trigger_script.R
Last active September 20, 2023 06:22
DiagrammeR (https://github.com/rich-iannone/DiagrammeR)— Trigger a script from inside a graph series and modify that graph series. Uses the 'create_series' and 'trigger_script' functions.
# Install the latest version of DiagrammeR from GitHub
devtools::install_github("rich-iannone/DiagrammeR")
# Ensure that the package is loaded
library("DiagrammeR")
# So, here's a script that essentially takes an empty graph series, and
# creates a new graph on each new day it is triggered. It will create
# random nodes each time it's triggered and add those nodes to the graph
# belonging to the current day. Throughout the script, '_SELF_' refers
@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-us-cities.R
Last active September 9, 2023 23:55
Demonstration code for plotting a graph of US cities along with country borders with the DiagrammeR R package.
# Installation
#install.packages("devtools")
devtools::install_github("rich-iannone/DiagrammeR")
library(DiagrammeR)
# Create a graph of border coordinates for USA, Canada, and Mexico
country_graph <- country_graph(iso_a2 = c("US", "CA", "MX"))
# Read in a CSV with US city data
@rich-iannone
rich-iannone / world-cities-diagrammer.R
Created October 5, 2015 07:08
Demonstration code for plotting a graph of world cities along with country borders with the DiagrammeR R package.
# 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