在javascript中使用plotly树形图

时间:2016-08-05 20:25:17

标签: javascript r plotly dendrogram dendextend

想与plotly.js制作IPython.embed()。是吗 可能?有人在javascript中实现了树形图吗?

1 个答案:

答案 0 :(得分:1)

不完全回答你的问题,但如果它有帮助 - 你可以使用R结合dendextend和plotly包来做到这一点。这是一个简单的例子:

install.packages(c("ggplot2", "dendextend", "plotly"))

library(dendextend)
# library(ggdendro)
# Create a complex dend:
dend <- iris[1:30,-5] %>% dist %>% hclust %>% as.dendrogram %>% 
  set("branches_k_color", k=3) %>% set("branches_lwd", c(1.5,1,1.5)) %>% 
  set("branches_lty", c(1,1,3,1,1,2)) %>%  
  set("labels_colors") %>% set("labels_cex", c(.9,1.2)) 
# plot the dend in usual "base" plotting engine:   
# plot(dend)
# Now let's do it in ggplot2 :)
ggd1 <- as.ggdend(dend)
library(ggplot2)
p <- ggplot(ggd1, offset_labels = -.1) # reproducing the above plot in ggplot2 :)

library(plotly)
ggplotly(p) %>% layout(showlegend = FALSE)

enter image description here