jokergoo / ComplexHeatmap

Make Complex Heatmaps
https://jokergoo.github.io/ComplexHeatmap-reference/book/
Other
1.29k stars 225 forks source link

I want to remove the main body of heatmap #1091

Open nolanjj opened 1 year ago

nolanjj commented 1 year ago

Please provide example datasets and the code you use. It will help me to understand your problem and help you!

help! I want to remove the main body of heatmap.Keep the cluster tree and comments at the top.What should I do

jokergoo commented 1 year ago

I guess you only want the dendrogram and the top annotation? Then you can do it in two steps:

  1. generate the clustering object:
set.seed(123)
m = matrix(rnorm(200), 20, 10)
hc = hclust(dist(t(m)))
  1. since you don't need the heatmap body but want to keep the dendrogram, you need to create a zero-row matrix:
m_zero = matrix(nrow = 0, ncol = 10)

Then creating the top annotation. Note here I move the annotation names to the left so that they will not overlap with the legend.

ha = HeatmapAnnotation(foo = 1:10, bar = anno_points(runif(10)),
    annotation_name_side = "left")

And finally put everything together:

Heatmap(m_zero, top_annotation = ha, cluster_columns = hc)
image
nolanjj commented 1 year ago
Heatmap(m_zero, top_annotation = ha, cluster_columns = hc)

Thank you! ComplexHeatmap is too powerful!