4

Want to make https://plot.ly/python/dendrogram/ with plotly.js. Is it possible? Has anyone implemented dendrogram in javascript?

Tal Galili
  • 24,605
  • 44
  • 129
  • 187
mei
  • 67
  • 9
  • Do you want to both the figurefactory function and the plot itself? Or do you provide the data and just want to plot it? – Maximilian Peters Aug 07 '16 at 17:55
  • data will be provided from external clustering routines and also consumed by a plotly heatmap from plotly.js. – mei Aug 29 '16 at 17:48

1 Answers1

2

Not exactly answers your question, but in case it helps - you can do it using R combined with the dendextend and plotly packages. Here is a quick example:

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

Tal Galili
  • 24,605
  • 44
  • 129
  • 187