jokergoo / ComplexHeatmap

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

EnrichedHeatmap scale annotation #1024

Open zor4x opened 1 year ago

zor4x commented 1 year ago

Hi, I was trying to plot a matrix using EnrichedHeatmap. I imported my original matrix:

`mat= as.normalizedMatrix(a, k_upstream = 1000, k_downstream = 1000, k_target = 1, extend = 1000, smooth = TRUE, keep = c(0, 0.95))
mat
Normalize signals to targets:
  Upstream 1000 bp (1000 windows)
  Downstream 1000 bp (1000 windows)
  Include target regions (1 window)
  255 target regions
`
`mat2= as.normalizedMatrix(b, k_upstream = 1000, k_downstream = 1000, k_target = 1, extend = 1000, smooth = TRUE, keep = c(0, 0.95))
mat2
Normalize signals to targets:
  Upstream 1000 bp (1000 windows)
  Downstream 1000 bp (1000 windows)
  Include target regions (1 window)
  255 target regions

`

and I plotted them using EnrichedHeatmap using this code: EnrichedHeatmap(mat2, name = "fragment ko", col = c("white", "red"), column_title = "Enrichment KO") + EnrichedHeatmap(mat, name = "fragment WT", col = c("white", "red"), column_title = "Enrichment of WT")

try_enrichedheatmap

My question is: I WOULD LIKE TO COMPARE THE TWO PLOTS USING THE SAME SCALE. HOW CAN I SET THE SCALE PARAMETERS TO BE THE SAME IN BOTH PLOTS? THANK YOU

jokergoo commented 1 year ago

YOU JUST NEED TO USE the SAME COLOR MAPPING FUNCTION FOR BOTH PLOTS :)

pooled = c(mat2, mat)
col_fun = circlize::colorRamp2(c(min(pooled), max(pooled)), c("white", "red"))
EnrichedHeatmap(mat2, name = "fragment ko", col = col_fun, column_title = "Enrichment KO") + 
    EnrichedHeatmap(mat, name = "fragment WT", col = col_fun, column_title = "Enrichment of WT")
zor4x commented 1 year ago

I'm sorry if I didn't explain myself well, I meant the scale of the annotation. maybe the picture is clearer now: WhatsApp Image 2022-12-09 at 11 48 08 I would have the same value to compare them properly :D

jokergoo commented 1 year ago

OK, then, in the function anno_enriched(), you can set the same value for ylim:

EnrichedHeatmap(mat2, name = "fragment ko", col = col_fun, column_title = "Enrichment KO",
    top_annotation = HeatmapAnnotation(enriched1 = anno_enriched(ylim = c(0, 0.3))) + 
  EnrichedHeatmap(mat, name = "fragment WT", col = col_fun, columçn_title = "Enrichment of WT",
    top_annotation = HeatmapAnnotation(enriched1 = anno_enriched(ylim = c(0, 0.3)))
zor4x commented 1 year ago

Thank you very much @jokergoo :D

zor4x commented 1 year ago

I have another question hoping that I'm not bothering you too much. I would to take the annotations of both heatmaps and color the area of overlap with a grey color. I will post you an example: overlaps Rplot

Thank you again @jokergoo

jokergoo commented 1 year ago

No , it is not possible. Do you want to emphasize the difference between the two lines?

Or you can do it without EnrichedHeatmap. The two lines can be obtained by

x1 = colMeans(m[group == "KO d8", ])
x2 = colMeans(m[group == "WT d8", ])
y = seq(-1000, 1000, length(x1))

And the area can be drawn by :

polygon(c(x1, rev(x2)), c(y, rev(y))
# or
grid.polygon(c(x1, rev(x2)), c(y, rev(y)), default.units = "native")