2013-07-24 27 views
0

我正在嘗試使用this awesome D3 layout可視化羣集樹!但是,它需要JSON格式的數據 - 我如何從R中的hclust-object轉換爲分層JSON結構?如何將hclust對象轉換爲D3的JSON?

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

我的谷歌搜索變成了這個hclustToTree函數返回一個看起來很有希望的清單 - 但我真的不知道從哪裏裏去。任何意見將不勝感激。

halfway <- hclustToTree(cl) 

回答

0

就快:

jsonTree <- toJSON(halfway) # part of the RJSONIO library 
+0

然後?你沒有得到你的D3對象...... – agstudy

+0

在這裏看D3的JSON:https://bitbucket.org/john2x/d3test/src/2ce4dd511244/d3/examples/data/flare.json你會的。 如果您的原始矩陣的行被命名,''name'''字段將被正確填寫。嘗試'rownames(m)< - 字母[1:10]'。 –