Question: Pheatmap row annotation multiple categories
0
gravatar for nitandressa
12 days ago by
Germany
nitandressa0 wrote:

Hello,

I know it is possible to generate a heatmap with row annotations using pheatmap, but is it possible to generate it when a row falls into 2 categories?

For example, in the code bellow, how can I add the side bar showing that tomato is both a fruit and used in a salad?

thanks in advance! :-)

library(pheatmap)

x = matrix(1:16, nrow = 4, 
    dimnames = list(c("banana","lime","carrot","tomato"), c("A1","A2","B1","B2")))
x

col_ann = data.frame(cbind(c("A1","A2","B1","B2"),c("A","A","B","B")))
colnames(col_ann)=c("sample","category1")
rownames(col_ann)=col_ann$sample
col_ann$sample<-NULL

row_ann = data.frame(cbind(c("banana","lime","carrot","tomato","tomato"),
                           c("fruit","fruit","salad","fruit","salad")))
colnames(row_ann)=c("food","category2")

ann_color = list("category1"=c("A"="yellow","B"="blue"),
                 "category2"=c("fruit"="red","salad"="green"))

pheatmap(x,
         cluster_rows = T,show_rownames = T, show_colnames=F, 
         border_color=NA, scale='row',
         annotation_col = col_ann,
         annotation_row = row_ann,
         annotation_colors = ann_color )
row annotation pheatmap R • 104 views
ADD COMMENTlink modified 11 days ago by manuel.belmadani1.1k • written 12 days ago by nitandressa0
1

Just create a separate category and colour for those that are both a fruit and salad? Otherwise, you may have to draw out how exactly you are visualising this should appear in your mind.

ADD REPLYlink written 11 days ago by Kevin Blighe51k
3
gravatar for manuel.belmadani
11 days ago by
Canada
manuel.belmadani1.1k wrote:

There's two ways I can see you do this. An easy way is to add just a "both" value (as I see now Kevin suggested in the comment.). In this case it makes sense since there's only two choices.

Using a category for cases that are "both"

Or if you really want to (or will have cases where "both" doesn't cut it because there's more categories), make Salad and Fruit binary annotations and encode "Yes" or "No" in each vector. Using separate columns for each annotations.

Code:

### Option one ####
library(pheatmap)

x = matrix(1:16, nrow = 4, 
           dimnames = list(c("banana","lime","carrot","tomato"), c("A1","A2","B1","B2")))
x

col_ann = data.frame(cbind(c("A1","A2","B1","B2"),c("A","A","B","B")))
colnames(col_ann)=c("sample","category1")
rownames(col_ann)=col_ann$sample
col_ann$sample<-NULL

row_ann = data.frame(c("fruit","fruit","salad","both"))
rownames(row_ann) <- c("banana","lime","carrot","tomato")

colnames(row_ann)=c("category2")

ann_color = list("category1"=c("A"="yellow","B"="blue"),
                 "category2"=c("fruit"="red","salad"="green", "both"="cyan"))

pheatmap(x,
         cluster_rows = T,show_rownames = T, show_colnames=F, 
         border_color=NA, scale='row',
         annotation_col = col_ann,
         annotation_row = row_ann,
         annotation_colors = ann_color )

### Option two ####

row_ann = data.frame(Fruit=c("Yes","No","No","Yes"),
                     Salad=c("No","No","Yes","Yes") )
rownames(row_ann) <- c("banana","lime","carrot","tomato")

ann_color = list("Fruit"=c("Yes"="red","No"="white"),
                 "Salad"=c("Yes"="green","No"="white"))

pheatmap(x,
         cluster_rows = T,show_rownames = T, show_colnames=F, 
         border_color=NA, scale='row',
         annotation_col = col_ann,
         annotation_row = row_ann,
         annotation_colors = ann_color )
ADD COMMENTlink written 11 days ago by manuel.belmadani1.1k
1
gravatar for Amar
11 days ago by
Amar470
Amar470 wrote:

If you add another column/variable into the row_ann then it will be annotated. eg:

row_ann$vegetable <- c("Veg", "Not", "Veg", "Veg", "Veg")

I can't test your code because pheatmap just isn't working for me. Not sure why...

ADD COMMENTlink written 11 days ago by Amar470

The code did not run for me, either.

ADD REPLYlink written 11 days ago by Kevin Blighe51k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1498 users visited in the last hour