Complexheatmap annotation legend
1
1
Entering edit mode
5.8 years ago
Prakash ★ 2.2k

Hi all,

could somebody help me in complexheatmap annotation legend.

hmap1 hmap2 hmap1+hmap2

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")

Rplot05 Rplot12 Rplot13

R rna-seq • 14k views
ADD COMMENT
1
Entering edit mode
5.8 years ago

Hey, please always show the code that you have used for this. If possible, provide data that allows for a reproducible example.

ADD COMMENT
1
Entering edit mode

Hi Kevin, I have updated the post with code and file Thanks

ADD REPLY
0
Entering edit mode

I see. Good work on the code so far.

You may have more success by plotting them via pushViewport():

pushViewport(viewport(layout=grid.layout(nr=1, nc=2)))

  pushViewport(viewport(layout.pos.row=1, layout.pos.col=1))
    draw(oxp_map1 + RowAnn, heatmap_legend_side="top", newpage = FALSE)
  popViewport()

  pushViewport(viewport(layout.pos.row=1, layout.pos.col=2))
    draw(oxp_map2 + RowAnn, heatmap_legend_side="top", newpage = FALSE)
  popViewport()

popViewport()

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)

ADD REPLY
2
Entering edit mode

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 !

ADD REPLY

Login before adding your answer.

Traffic: 1930 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6