Is there a way to plot dendrogram?

Hierarchical clustering is quite simple in Julia by using hclust() in the Clustering package,
but plotting the result in Julia does not seem to be straightforward for me as in Python.
(see SciPy Hierarchical Clustering and Dendrogram Tutorial | Jörn's Blog)

Grateful to any suggestion from you.

1 Like

Not that I know of - but this would be an excellent contribution to a package like PlotRecipes, or as a plotting recipe in Clustering itself if they are happy to have it there.

PlotRecipes already has recipes for plotting graph-like objects - it may be possible to create a plot recipe that uses this existing functionality.

You might want to look at https://github.com/jangevaare/PhyloTrees.jl. There’s an example in the Plots docs: https://juliaplots.github.io/ecosystem/

Even if this doesn’t directly solve your problem, you might be able to get ideas from it.

I often do my computation in Julia but then use the PyCall package to call a mature Python visualization routine on that data. PyCall is really easy to use.

1 Like

eg,

using PyCall
using PyPlot
@pyimport scipy.cluster.hierarchy as hierarchy
hierarchy.dendrogram([0 1 .7 2])

2 Likes

The linkage function in Scipy follows MATLAB-style output while hclust() in Clustering.jl follows R-style one.

Since MATLAB-style output is more compatible in both suggestions above, I hope that the hclust() in Clustering.jl will be revised sometime (Sorry if the JuliaStat Project favors R-Style). Changing the output format itself is not difficult but a bit bothering for someone :slight_smile:

Kescobo have a nice implementation, just was not merged. It works directly with Hclust type.

https://gist.github.com/kescobo/799bf484e96a854857cb65f2c5685693

https://github.com/JuliaPlots/StatPlots.jl/issues/73

2 Likes

You can do this using StatsPlots now:

https://docs.juliaplots.org/latest/generated/statsplots/#Dendrograms