0

I'm attempting to visualize a cluster tree using this awesome D3 layout! However, it needs data in JSON format - how do I go from a hclust-object in R to a hierarchical JSON structure?

set.seed(123)
m <- matrix(runif(100), nrow=10)
cl <- hclust(dist(m))
plot(cl)

My googling turned up this hclustToTree function which returns a list that looks promising - but I don't really know where to go from there. Any advice would be much appreciated.

halfway <- hclustToTree(cl)
jenswirf
  • 7,087
  • 11
  • 45
  • 65

1 Answers1

1

You're almost there:

jsonTree <- toJSON(halfway)  # part of the RJSONIO library
Scott Ritchie
  • 10,293
  • 3
  • 28
  • 64
  • Looking at the D3 JSON here: https://bitbucket.org/john2x/d3test/src/2ce4dd511244/d3/examples/data/flare.json You will. The `"name"` field will be correctly be filled out if the rows of your original matrix are named. Try `rownames(m) <- letters[1:10]`. – Scott Ritchie Jul 24 '13 at 16:47