Skip to content

Instantly share code, notes, and snippets.

clickme D3 straight from R

An interactive longitudinal heatmap next to a parallel coordinates plot, one of the pre-installed clickme examples

@nachocab
nachocab / d3.min.js
Last active December 15, 2015 01:18
example force directed viz
(function(){function t(t){return t.target}function n(t){return t.source}function e(t,n){try{for(var e in n)Object.defineProperty(t.prototype,e,{value:n[e],enumerable:!1})}catch(r){t.prototype=n}}function r(t){for(var n=-1,e=t.length,r=[];e>++n;)r.push(t[n]);return r}function i(t){return Array.prototype.slice.call(t)}function u(){}function a(t){return t}function o(){return!0}function c(t){return"function"==typeof t?t:function(){return t}}function l(t,n,e){return function(){var r=e.apply(n,arguments);return arguments.length?t:r}}function s(t){return null!=t&&!isNaN(t)}function f(t){return t.length}function h(t){return t.trim().replace(/\s+/g," ")}function d(t){for(var n=1;t*n%1;)n*=10;return n}function g(t){return 1===t.length?function(n,e){t(null==n?e:null)}:t}function p(t){return t.responseText}function m(t){return JSON.parse(t.responseText)}function v(t){var n=document.createRange();return n.selectNode(document.body),n.createContextualFragment(t.responseText)}function y(t){return t.responseXML}function M(){}
(function(){function t(t){return t.target}function n(t){return t.source}function e(t,n){try{for(var e in n)Object.defineProperty(t.prototype,e,{value:n[e],enumerable:!1})}catch(r){t.prototype=n}}function r(t){for(var n=-1,e=t.length,r=[];e>++n;)r.push(t[n]);return r}function i(t){return Array.prototype.slice.call(t)}function u(){}function a(t){return t}function o(){return!0}function c(t){return"function"==typeof t?t:function(){return t}}function l(t,n,e){return function(){var r=e.apply(n,arguments);return arguments.length?t:r}}function s(t){return null!=t&&!isNaN(t)}function f(t){return t.length}function h(t){return t.trim().replace(/\s+/g," ")}function d(t){for(var n=1;t*n%1;)n*=10;return n}function g(t){return 1===t.length?function(n,e){t(null==n?e:null)}:t}function p(t){return t.responseText}function m(t){return JSON.parse(t.responseText)}function v(t){var n=document.createRange();return n.selectNode(document.body),n.createContextualFragment(t.responseText)}function y(t){return t.responseXML}function M(){}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Force directed</title>
<script src="ractives/force_directed/external/d3.min.js"></script>
<link href="ractives/force_directed/external/main.css" rel="stylesheet">
</head>
<body>
@nachocab
nachocab / avoid_pdf_tables
Created January 27, 2013 14:52
A request to use text files instead of pdfs to share supplementary material.
Dear Doctor ____,
I wanted to thank you for your published paper on _____. It provides a significant contribution to the field of ______, and I hope you will continue publishing similar work in the future. I have been trying to build on your work, integrating your results with my own research. Unfortunately, this has proved challenging because the supplementary tables were published in a .pdf format, which requires manual copying and pasting, it doesn't preserve the original format, and is prone to character encoding errors.
In future publications, you could easily avoid these issues by making the supplementary tables available in files of comma-separated values (.csv), or plain-text format. Figshare is a popular online resource used by many authors to publish this type of data in a way that is easily citeable. You can read more about it here: http://figshare.com/features. Feel free to share it with your colleagues.
Thank you for making scientific research more accessible.
Best,
____
@nachocab
nachocab / heatmap3.R
Created October 8, 2012 15:06
heatmap 3 revised
# EXAMPLE USAGE
# example of colsidecolors rowsidecolors (single column, single row)
mat <- matrix(1:100, byrow=T, nrow=10)
column_annotation <- sample(c("red", "blue", "green"), 10, replace=T)
column_annotation <- as.matrix(column_annotation)
colnames(column_annotation) <- c("Variable X")
row_annotation <- sample(c("red", "blue", "green"), 10, replace=T)
row_annotation <- as.matrix(t(row_annotation))
<!DOCTYPE html>
<html>
<head>
<script src='http://mbostock.github.com/d3/d3.js'></script>
</head>
<body>
<script type="text/javascript">
var textElems = ["text1","text2"]
var x = d3.scale.ordinal().domain(d3.range(textElems.length)).rangeBands([0, 120]);
<!DOCTYPE html>
<html>
<head>
<script src='../js/d3.js'></script>
<script src='../js/underscore.js'></script>
</head>
<body>
<script type="text/javascript">
var textElems = ["text1","text2"]
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
</head>
<body>
<script type="text/javascript">
var textElems = ["text1","text2"]
var x = d3.scale.ordinal().domain(d3.range(textElems.length)).rangeBands([0, 120]);
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
</head>
<body>
<script type="text/javascript">
var data = [-1,0,1]
var rect_size = 25; //px