My first D3 map showing my travel across the US. This visualization was built by modifying choropleth example code by Scott Murray, tooltip example code by Malcolm Maclean, and legend code example by Mike Bostock.
license: gpl-3.0 |
A dendrogram is a common way to represent hierarchical data. For Python users, Scipy has a hierarchical clustering module that performs hierarchical clustering and outputs the results as dendrogram plots via matplotlib. When it's time to make a prettier, more customized, or web-version of the dendogram, however, it can be tricky to use Scipy's dendrogram to create a suitable visualization. My preferred method of visualizing data -- especially on the web -- is D3. This example includes a script to convert a Scipy dendrogram into JSON format used by D3's cluster
method.
In the example, I cluster six genes by their expression values from two experiments. You can easily replace that data with your own, larger data set, to harness the power of both Scipy and D3 for analyzing hierarchical data. The D3 code I used to generate this example is straigh
library(rjson) | |
#convert output from hclust into a nested JSON file | |
HCtoJSON<-function(hc){ | |
labels<-hc$labels | |
merge<-data.frame(hc$merge) | |
for (i in (1:nrow(merge))) { |
# $Id: Nielsen2012Python_case.py,v 1.2 2012/09/02 16:55:25 fn Exp $ | |
# Define a url as a Python string (note we are only getting 100 documents) | |
url = "http://wikilit.referata.com/" + \ | |
"wiki/Special:Ask/" + \ | |
"-5B-5BCategory:Publications-5D-5D/" + \ | |
"-3FHas-20author%3DAuthor(s)/-3FYear/" + \ | |
"-3FPublished-20in/-3FAbstract/-3FHas-20topic%3DTopic(s)/" + \ | |
"-3FHas-20domain%3DDomain(s)/" + \ | |
"format%3D-20csv/limit%3D-20100/offset%3D0" |
#!/usr/bin/env python | |
# based on http://stackoverflow.com/questions/7052947/split-95mb-json-array-into-smaller-chunks | |
# usage: python json-split filename.json | |
# produces multiple filename_0.json of 1.49 MB size | |
import json | |
import sys | |
with open(sys.argv[1],'r') as infile: | |
o = json.load(infile) |