How to regroup columns in R using heatmap.2 or pheatmap ?
1
0
Entering edit mode
6.8 years ago
Björn ▴ 110

Using following heatmap.2 command

heatmap.2(highly_variable_lcpm,labRow = y2$genes$genes, Rowv = TRUE, col=rev(morecols(20)),trace="none",tracecol = "black",main="Top 20 most variable genes across samples",cex.main=0.6, ColSideColors=group.col,scale="row",margins=c(10,9))

I got the following graph ![heatmap][1][1]: https://ibb.co/iiN257 The colors in column header indicate similar group which are 5 different colors (groups). How to make the samples in each group together so as to show group-wise variation (which is supervised clustering). Thanks

edgeR heatmap.2 pheatmap • 11k views
ADD COMMENT
0
Entering edit mode

If your input samples are in the correct order, use dendrogram="row" to turn off the column-wise clustering

ADD REPLY
0
Entering edit mode

or, if your input matrix is ordered try Rowv=False

ADD REPLY
0
Entering edit mode

The row is not in order so adding

Colv=FALSE, dendrogram="row"

did not really help . E.g. my samples are as A A A B B B A A A C C C N N N. I need to find a way to bring all 6 "A" together.

ADD REPLY
0
Entering edit mode

Have you considered then reordering them

ADD REPLY
0
Entering edit mode

That was my question , how ?

ADD REPLY
0
Entering edit mode

Re-order them in your actual data-matrix, i.e., before you even apply the heatmap.2 function, and then use Colv and dendrogram as per Buffo

Something like:

sample.order <- A A A B B B A A A C C C N N N *pseudocode
highly_variable_lcpm.ordered <- highly_variable_lcpm[,sample.order]

heatmap.2(highly_variable_lcpm.ordered, ...)
ADD REPLY
4
Entering edit mode
6.8 years ago
h.mon 35k

Reorder the matrix by column names:

data <- data[ , order( colnames( data ) ) ]

Then plot the heatmap with Colv=FALSE, dendrogram="row".

I wouldn't try to force the groupings, though, if your treatments are not clustering, this reflects the structure of the data and is important to the interpretation of the results.

ADD COMMENT

Login before adding your answer.

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