about using the names of the rows and columns in ComplexHeatmap
1
0
Entering edit mode
Bogdan ▴ 670
@bogdan-2367
Last seen 13 months ago
Palo Alto, CA, USA


Dear all,

after starting working with the package ComplexHeatmap, i would like to add a simple question (with my apologies if I missed the answer in the package documentation). The question is the following:

shall we have numerical matrix/dataframe (with or without ROWNAMES or COLNAMES), is the ORDER of the ROWS or the COLUMNS by default CONNECTED to a data frame of ANNOTATIONS in HeatmapAnnotation () ?

Or shall we include the ROWNAMES and the COLNAMES in the initial numerical matrix/dataframe,
and use identical NAMES (as the ROWNAMES and COLNAMES) in the HeatmapAnnotation() dataframe for precise annotations ?

I am asking the question because sometimes we have to FILTER the initial MATRIX/DATAFRAME (function of various criteria), and we'd like to keep the same annotations in HeatmapAnnotation for the remaining ROWS and COLUMNS ?

I will post an example in a few minutes. Many thanks,

-- bogdan

complexheatmap • 2.4k views
ADD COMMENT
0
Entering edit mode
Bogdan ▴ 670
@bogdan-2367
Last seen 13 months ago
Palo Alto, CA, USA

Continuing my previous email with an example : starting from the dataframe MAT and some annotations in DF/HA :

library(ComplexHeatmap)
library(circlize)

set.seed(123)

mat = cbind(rbind(matrix(rnorm(16, -1), 4), matrix(rnorm(32, 1), 8)),
            rbind(matrix(rnorm(24, 1), 4), matrix(rnorm(48, -1), 8)))

# permute the rows and columns
mat = mat[sample(nrow(mat), nrow(mat)), sample(ncol(mat), ncol(mat))]

rownames(mat) = paste0("R", 1:12)
colnames(mat) = paste0("C", 1:10)

########## 12 ROWS
########## 10 COLUMNS

Heatmap(mat)
Heatmap(as.data.frame(mat))

#######

df = data.frame(type = c(rep("a", 5), rep("b", 5)))
ha = HeatmapAnnotation(df = df,
                       col = list(type = c("a" =  "red", "b" = "blue")))

ha
draw(ha, 1:10) 

##########

Heatmap(mat,  cluster_rows = FALSE,
              cluster_columns = FALSE,
              top_annotation = ha,
              bottom_annotation = ha)

 

However, if we SUBSET the INITIAL MATRIX :

mat2 <- mat[c(1,2,3,6:12), c(1,2,3,6:10)]

then the function Heatmap(mat2) will shift the RED COLOR on the COLUMNS C6 and C7 (below). We would like to keep the BLUE color on the COLUMNS C6 and C7. Thank you very much !

Heatmap(mat2, cluster_rows = FALSE,
                           cluster_columns = FALSE,
                           top_annotation = ha,
                           bottom_annotation = ha)

 

 

 

 

 

 

##

ADD COMMENT

Login before adding your answer.

Traffic: 657 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