Skip to content

Instantly share code, notes, and snippets.

View guoruijiao's full-sized avatar

Ruijiao Guo guoruijiao

  • Sunnyvale, CA
View GitHub Profile
@guoruijiao
guoruijiao / README.md
Created November 23, 2019 04:04 — forked from michellechandra/README.md
Basic US State Map - D3
@guoruijiao
guoruijiao / .block
Created February 12, 2016 06:48 — forked from mbostock/.block
Collapsible Indented Tree
license: gpl-3.0
@guoruijiao
guoruijiao / README.md
Created February 12, 2016 06:24 — forked from mdml/README.md
Dendrograms: Convert from Scipy to D3

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

@guoruijiao
guoruijiao / HClust_Dendogram.R
Created February 12, 2016 06:12 — forked from jamesthomson/HClust_Dendogram.R
R HClust to d3.js Dendogram
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))) {
@guoruijiao
guoruijiao / Nielsen2012Python_case.py
Created February 9, 2016 18:12 — forked from fnielsen/Nielsen2012Python_case.py
Text mining example in Python
# $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)