Skip to content

Add hierarchical clustering and dendrograms to Heatmap #110

Description

@VinzentRisch

Add optional hierarchical clustering for heatmap rows and columns, including coordinated row and column dendrograms.

  • SciPy can handle the clustering calculation, but this introduces a SciPy dependency.
  • All distance metrics and linkage methods that are exposed in SciPy can be included as options for the parameters distance and method parameters. Default distance = euclidian, method = complete.
  • Parameter "clustering" with options: features, samples, both, none

High-level workflow:

input matrix
  → optionally standardize values
  → calculate row and column pairwise distances with scipy.spatial.distance.pdist
  → compute hierarchical linkage with scipy.cluster.hierarchy.linkage
  → obtain dendrogram geometry and leaf order with scipy.cluster.hierarchy.dendrogram(no_plot=True)
  → reorder heatmap rows and columns by leaf order
  → convert SciPy dendrogram coordinates into line-segment data
  → render the heatmap and dendrogram line segments in Vega

The Vega specification can use generic rule marks to render every dendrogram branch from the generated segment data; branches do not need to be manually hard-coded.

Codex code Example:
scipy-vega-clustered-heatmap.py

Plot:

Image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions