I am generating a heatmap using R.
I used the hclust
function and got the error:
Colv dendrogram doesn't match size of x
.
Below is my code, it works perfectly with a square matrix. Now my input matrix is 400x2000
. Can someone tell me why I am getting this error?
data <- read.table("mydata.txt",sep="\t",header=TRUE,row.names=1)
data_matrix <- data.matrix(data)
library(gplots)
library("RColorBrewer")
colors <- colorRampPalette(rev(brewer.pal(9, "Blues")) )(255)
hc_dist= dist(data_matrix)
hc_clust= hclust(hc_dist)
hr_dist= dist(t(data_matrix))
hr_clust= hclust(hr_dist)
heatmap.2(data_matrix, col=brewer.pal(11,"RdBu"), labRow=NA, density.info="none", scale="row",trace="none",Colv=as.dendrogram(hc_clust), Rowv=as.dendrogram(hr_clust))
Error in heatmap.2(data_matrix, col = brewer.pal(11, "RdBu"), labRow = NA,:Colv dendrogram doesn't match size of x