Entering edit mode
5.8 years ago
Prakash
★
2.2k
Hi all,
could somebody help me in complexheatmap annotation legend.
Here if I merge hmap1 and hmap2, the legend for hmap2 goes missing. I am using complexheatmap version 1.99.5.
oxp_map1 file1
oxp_map2 file2
anno <- as.data.frame(colnames(oxp_exp_X_scaled[,1:4]))
colnames(anno) <- "Sample"
anno$Vector <- c("Empty","KD","Empty","KD")
anno$Time <- c("0h","0h","6h","6h")
ha = HeatmapAnnotation(df=anno[,c(2:3)],
col = list(Vector = c("Empty"="red","KD"="grey"),
Time = c("0h"="dimgray","6h"="brown")),
annotation_height = unit(c(0.5, 0.5), "cm"),
show_annotation_name = TRUE,
annotation_name_offset = unit(2, "mm"),
annotation_name_rot = c(0, 0))
oxp_map1 <- Heatmap(oxp_exp_X_scaled[,1:4],km = 1,
name="Z-score",
col= colorRamp2(c(-2,-1,0,1,2),c("blue","skyblue","white","lightcoral","red")),
heatmap_legend_param=list(at=c(-2,-1,0,1,2),color_bar="continuous",
legend_direction="horizontal", legend_width=unit(5,"cm"),
title_position="topcenter", title_gp=gpar(fontsize=10, fontface="bold")),
#Split heatmap rows by gene family
split = oxp_exp_X_scaled[,5],
border = TRUE,
cluster_rows=TRUE,
show_row_dend=TRUE,
row_title_side="left",
row_title_gp=gpar(fontsize=8),
show_row_names=TRUE,
row_names_side="right",
#Column annotation configuratiions
cluster_columns=FALSE,
show_column_dend=TRUE,
column_title="X",
column_title_side="top",
column_title_gp=gpar(fontsize=10, fontface="bold"),
show_column_names=FALSE,
#Dendrogram configurations: columns
clustering_distance_columns="euclidean",
clustering_method_columns="complete",
column_dend_height=unit(10,"mm"),
#Dendrogram configurations: rows
clustering_distance_rows="euclidean",
clustering_method_rows="complete",
row_dend_width=unit(10,"mm"),
top_annotation = ha,
show_heatmap_legend = TRUE)
#################################################
# Row annotation
RowAnn <- data.frame(paste0("Complex",oxp_exp_Y_scaled[,7]))
colnames(RowAnn) <- c("Complex")
RowAnn <- HeatmapAnnotation(df=RowAnn, which="row")
# Top annotation
anno <- as.data.frame(colnames(oxp_exp_Y_scaled[,1:6]))
colnames(anno) <- "Sample"
anno$Vector <- c("Empty","KD","Empty","KD","Empty","KD")
anno$Time <- c("0h","0h","2h","2h","6h","6h")
ha2 = HeatmapAnnotation(df=anno[,c(2:3)],
col = list(Vector = c("Empty"="red","KD"="blue"),
Time = c("0h"="dimgray","2h"="gray","6h"="brown")),
annotation_height = unit(c(0.5, 0.5), "cm"),
show_annotation_name = TRUE,
annotation_name_offset = unit(2, "mm"),
annotation_name_rot = c(0, 0))
oxp_map2 <- Heatmap(oxp_exp_Y_scaled[,1:6],km = 1,
name="Z-score",
col= colorRamp2(c(-2,-1,0,1,2),c("blue","skyblue","white","lightcoral","red")),
heatmap_legend_param=list(at=c(-2,-1,0,1,2),color_bar="continuous",
legend_direction="horizontal", legend_width=unit(5,"cm"),
title_position="topcenter", title_gp=gpar(fontsize=10, fontface="bold")),
#Split heatmap rows
split = oxp_exp_Y_scaled[,7],
border = TRUE,
#Row annotation configurations
cluster_rows=TRUE,
show_row_dend=TRUE,
roww_title_side="left",
row_title_gp=gpar(fontsize=8),
show_row_names=TRUE,
row_names_side="right",
#Column annotation configuratiions
cluster_columns=FALSE,
show_column_dend=TRUE,
column_title="Y",
column_title_side="top",
column_title_gp=gpar(fontsize=10, fontface="bold"),
column_names_gp = gpar(fontsize = 20, fontface="bold"),
show_column_names=FALSE,
#Dendrogram configurations: columns
clustering_distance_columns="euclidean",
clustering_method_columns="complete",
column_dend_height=unit(10,"mm"),
#Dendrogram configurations: rows
clustering_distance_rows="euclidean",
clustering_method_rows="complete",
row_dend_width=unit(10,"mm"),
top_annotation = ha2)
draw(oxp_map1+oxp_map2+RowAnn ,heatmap_legend_side="top")
Hi Kevin, I have updated the post with code and file Thanks
I see. Good work on the code so far.
You may have more success by plotting them via
pushViewport()
:Please take a look at the example, here: https://support.bioconductor.org/p/87318/#87414 (the answer given in that thread is the author of ComplexHeatmap)
It did work but in different way since pushViewport will only help in plotting multiple plot, but actually my concern was why the legend goes missing when i merge the plot. anyway for time being i have addressed my issue.
Thanks a lot Kevin , I really appreciate your help !