Cluster heat map in Julia


#1

A cluster heat map is a way of plotting a matrix. Here is an example: https://en.wikipedia.org/wiki/File:Heatmap.png (I don’t need the trees).

The interesting part is that rows and columns are reordered so that similar values are closer together.

Is there a package in Julia providing this functionality?


#2

Does this work?

using GR
x = rand(20,20);
heatmap(x)

However, I am not sure which function in Plots.jl is used to access the GR heatmap.


#3

Just heatmap.

https://juliaplots.github.io/examples/gr/#heatmap-categorical-axes-and-aspect_ratio


#4

Note though that this does not address the issue of clustering. I’m pretty sure that you’d need to cluster the matrix first, then plot the heatmap. The process of clustering a matrix by rows and columns is called biclustering, and is “soon to be implemented” in MLMetrics.jl.


#5

For the clustering you can use the Clustering package:

using Clustering, Distributions

# build a matrix with 4 classes
μ = rand(4)*20
μ = StatsBase.sample(μ,100)
M = hcat([rand(Normal(μ,1),200) for μ in μ]...)

# cluster it
c = kmeans(M,4)
idx =  sortperm(assignments(c))
M = M[:,idx]

# use you favorite heatmap plot
image(M)

#6

That only works to sort the columns, though.