How to Draw a Dendrogram in Julia
Explanation
When attempting to draw a dendrogram by using the plot()
function after performing hierarchical clustering with hclust()
on the given data, the following error occurs.
using Clustering
using Distances
using Plots
a = rand(2, 10)
D_a = pairwise(Euclidean(), a, a)
SL = hclust(D_a, linkage=:single)
dendrogram = plot(SL)
ERROR: LoadError: Cannot convert Hclust{Float64} to series data for plotting
To draw a dendrogram, one should use StatsPlots.jl
instead of Plots.jl
.
using StatsPlots
dendrogram = plot(SL)
savefig(dendrogram, "julia_dendrogram.png")