Skip to content

Instantly share code, notes, and snippets.

library(igraph)
library(colorBreweR)
g <- watts.strogatz.game(1, 100, 5, 0.05)
V(g)$degree <- degree(g)
V(g)$betweenness <- betweenness(g)
V(g)$closeness <- closeness(g)
V(g)$eigen <- eigen_centrality(g)$vector
@ngopal
ngopal / vanham_wattenburg.R
Last active February 24, 2016 00:45
A playground where I was implementing the algorithm detailed in the "Centrality Based Visualization of Small World Graphs"
library(igraph)
g <- watts.strogatz.game(1, 100, 5, 0.05)
#g <- erdos.renyi.game(100, 3/100)
plot(g, vertex.size=2, vertex.label=NA)
# Calculate edge betweenness
eb <- cbind(E(g),edge_betweenness(g))
ebt <- eb[order(eb[,2], decreasing = T),]
head(ebt)
@ngopal
ngopal / graph_edges.csv
Created December 2, 2015 19:45
A gist showing how to setup a small multiple implementation of a basic D3 force directed graph. The code also contains an example of how to read in a CSV file that contains graph edges. The JSBIN example lives here: http://jsbin.com/hinixi/2
source target
A1 A2
A2 A3
A2 A4
@ngopal
ngopal / index.html
Created November 4, 2015 04:14
quick one-off script to visualize a sif format file in D3
<html>
<head>
<style>
.node {
stroke: #fff;
stroke-width: 1.5px;
}
.link {
@ngopal
ngopal / CIE1931xy_blank.svg
Last active October 23, 2015 23:04
Posting a github repo as a gist to include it on a webpage in an iframe
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ngopal
ngopal / RandomNetwork.js
Created September 22, 2015 21:02
Some functions to generate a random network. Returned objected is ready for plug-and-play use with D3 force-directed graph examples
function initializeNodes(n) {
var arr = [];
for (var i = 0; i < n; i++) {
arr.push({id:i});
}
return arr;
}
function getRandomArbitrary(min, max) {
@ngopal
ngopal / MyVariantUIPrototype.js
Created September 15, 2015 23:57
A rapid prototype for an interface for MyVariant.info JSON data
var myvar = {
"hits": [
{
"_id": "chr1:g.218631822G>A",
"_score": 17.48471,
"dbsnp": {
"allele_origin": "unspecified",
"alleles": [
{
"allele": "G",
@ngopal
ngopal / force-directed.js
Created September 10, 2015 21:18
Working on a simply implemented force-directed layout implementation
//constants
var K_r = 60;
var L = 50;
var delta_t = 0.4;
var MAX_DISP_SQ = 20;
var width = 300;
var height = width;
var body = d3.select('body');
@ngopal
ngopal / index.html
Last active August 29, 2015 14:22
Just making silly pretty pictures. I guess you might be able to learn a thing or two about D3 transitions if you don't already know how they work.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<script src="http://d3js.org/d3.v3.min.js"></script>
</head>
<body>
<script type="text/javascript">
var margin = {"left":20, "top":10, "right":20, "bottom":20}
@ngopal
ngopal / visual_encodings.json
Created May 4, 2015 21:13
visual encodings
[
{
"Encoding" : "placement-position",
"Ordered" : "true",
"UsefulVales" : "inf",
"Quantitative" : "true",
"Ordinal" : "true",
"Categorical" : "true",
"Relational" : "true"
},