我正在尝试创建基因组关系矩阵的热图,其中使用分层聚类方法对行和列进行聚类。
我正在尝试以下脚本:
setwd("C:\\Users\\Amanda\\Documents\\Mestrado- ESALQ\\RESULTADOS_FINAL_2017\\LD_Coutinho\\relacionamento_ind")
data_orig<-as.data.frame(read.table("G_Orig.txt"))
colnames(data_orig)<-c("id1","id2","Relationship")
nrow(data_orig) #156816
################Transform into matrix with animals in row and column
library(reshape)
data<-cast(data_orig, id1 ~ id2)
y<-as.data.frame(data[,-397])
#Run heatmap.2 on this matrix
library(gplots)
test <- heatmap.2(as.matrix(y))
y[rev(test$rowInd), test$colInd]
## Row clustering (adjust here distance/linkage methods to what yo need)
hr <- hclust(as.dist(1-cor(t(y), method="pearson")),
method="complete")
## Column clustering (adjust here distance/linkage methods to what you
need!)
hc <- hclust(as.dist(1-cor(y, method="spearman")), method="complete")
## Plot heatmap
heatmap.2(y, Rowv=as.dendrogram(hr), Colv=as.dendrogram(hc),
scale="row", density.info="none", trace="none")
## Return matrix with row/column sorting as in heatmap
y[rev(hr$labels[hr$order]), hc$labels[hc$order]]
我的data_orig是一个包含3列的数据:ind1,ind2和relationship。
我该怎么办?