# Is there a way to plot dendrogram?

**URL:** https://discourse.julialang.org/t/is-there-a-way-to-plot-dendrogram/2197
**Category:** General Usage
**Tags:** plotting
**Created:** [February 21, 2017, 2:19am UTC](https://discourse.julialang.org/t/is-there-a-way-to-plot-dendrogram/2197 "2017-02-21T02:19:12Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![leejm516](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leejm516/32/8219_2.png) [@leejm516](https://discourse.julialang.org/u/leejm516)
#### Post date: [February 21, 2017, 2:19am UTC](https://discourse.julialang.org/t/is-there-a-way-to-plot-dendrogram/2197/1 "2017-02-21T02:19:12Z")

</div>

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](https://joernhees.de/blog/2015/08/26/scipy-hierarchical-clustering-and-dendrogram-tutorial/#Perform-the-Hierarchical-Clustering))

Grateful to any suggestion from you.

---

<div class="post-metadata">

### Author: ![swt30](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/swt30/32/4667_2.png) [@swt30](https://discourse.julialang.org/u/swt30)
#### Post date: [February 21, 2017, 10:40am UTC](https://discourse.julialang.org/t/is-there-a-way-to-plot-dendrogram/2197/2 "2017-02-21T10:40:00Z")

</div>

Not that I know of - but this would be an excellent contribution to a package like [PlotRecipes](https://github.com/JuliaPlots/PlotRecipes.jl), or as a plotting recipe in Clustering itself if they are happy to have it there.

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [February 21, 2017, 11:20am UTC](https://discourse.julialang.org/t/is-there-a-way-to-plot-dendrogram/2197/3 "2017-02-21T11:20:06Z")

</div>

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

---

<div class="post-metadata">

### Author: ![tbreloff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbreloff/32/68_2.png) [@tbreloff](https://discourse.julialang.org/u/tbreloff)
#### Post date: [February 21, 2017, 3:10pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-plot-dendrogram/2197/4 "2017-02-21T15:10:54Z")

</div>

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

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

---

<div class="post-metadata">

### Author: ![malmaud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/malmaud/32/29_2.png) [@malmaud](https://discourse.julialang.org/u/malmaud)
#### Post date: [February 21, 2017, 5:28pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-plot-dendrogram/2197/5 "2017-02-21T17:28:34Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![malmaud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/malmaud/32/29_2.png) [@malmaud](https://discourse.julialang.org/u/malmaud)
#### Post date: [February 21, 2017, 5:39pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-plot-dendrogram/2197/6 "2017-02-21T17:39:24Z")

</div>

eg,

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

```

 ![](https://global.discourse-cdn.com/julialang/original/3X/3/5/35bcc31aa3317f5e0d5f9c0f81a7c2baba63e524.png)

---

<div class="post-metadata">

### Author: ![leejm516](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leejm516/32/8219_2.png) [@leejm516](https://discourse.julialang.org/u/leejm516)
#### Post date: [February 24, 2017, 8:30am UTC](https://discourse.julialang.org/t/is-there-a-way-to-plot-dendrogram/2197/7 "2017-02-24T08:30:57Z")

</div>

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 🙂

---

<div class="post-metadata">

### Author: ![jwu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jwu/32/3775_2.png) [@jwu](https://discourse.julialang.org/u/jwu)
#### Post date: [November 5, 2017, 2:36am UTC](https://discourse.julialang.org/t/is-there-a-way-to-plot-dendrogram/2197/8 "2017-11-05T02:36:17Z")

</div>

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

[https://gist.github.com/kescobo/799bf484e96a854857cb65f2c5685693](https://gist.github.com/kescobo/799bf484e96a854857cb65f2c5685693)

[https://github.com/JuliaPlots/StatPlots.jl/issues/73](https://github.com/JuliaPlots/StatPlots.jl/issues/73)

---

<div class="post-metadata">

### Author: ![Caitlin\_Lienkaemper](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/caitlin_lienkaemper/32/50996_2.png) [@Caitlin\_Lienkaemper](https://discourse.julialang.org/u/Caitlin_Lienkaemper)
#### Post date: [June 23, 2023, 3:27pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-plot-dendrogram/2197/9 "2023-06-23T15:27:42Z")

</div>

You can do this using StatsPlots now:

[https://docs.juliaplots.org/latest/generated/statsplots/#Dendrograms](https://docs.juliaplots.org/latest/generated/statsplots/#Dendrograms)
