Skip to content

plot(tree, what = "heatmap"): draw a giottoTree's own correlation matrix - #156

Merged
jiajic merged 1 commit into
gsourcefrom
feat/plot-giotto-tree
Oct 1, 2026
Merged

jiajic merged 1 commit into
gsourcefrom
feat/plot-giotto-tree

Conversation

@jiajic

@jiajic jiajic commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

A plot() method for the giottoTree returned by Giotto::calculateClusterTree():

  • what = "tree" (the default): the plain hclust plot, as before. ... passes through, so plot(tree, hang = -1) keeps working.
  • what = "heatmap": draws attr(tree, "cor_matrix") in leaf order, with the tree's branches on both axes (ComplexHeatmap, already in Suggests). The title names the correlation type and the feature count.

This is the one place where drawing the attached matrix is honest: it's the matrix the branches were built from, so colors and branches can't disagree. It describes the tree, not whatever object is current. For correlations recomputed from an object in a tree's order, use showClusterHeatmap(cluster_custom_order = tree$labels[tree$order]) (#154), which deliberately draws no branches. A tree without its matrix errors and points there.

Why it lives here

Drawing belongs in GiottoVisuals, next to plotClusterTree() and showClusterHeatmap(). An S3 class is just a string, so the method is registered here (S3method(plot, giottoTree)) with no dependency on Giotto. Giotto imports GiottoVisuals, so loading Giotto, where trees are made, registers it. The contract is the attributes Giotto documents on calculateClusterTree() (params, cor_matrix), and plotClusterTree() already reads params the same way.

This replaces giotto-suite/Giotto#1324, which put the same method in Giotto.

Verification

In test-plot-cluster-tree.R:

  • plot(tree, hang = -1) returns the tree with no warning
  • the heatmap's matrix is exactly the tree's cor_matrix in leaf order, and its row dendrogram is the tree
  • a tree without its matrix errors with a pointer to showClusterHeatmap(cluster_custom_order =)

In a plain user session loading Giotto, getS3method("plot", "giottoTree") resolves to GiottoVisuals, and both what options dispatch. All 47 tests pass (106 expectations).

🤖 Generated with Claude Code

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant