R-热图。2:对行和列重新排序

R-热图。2:对行和列重新排序,r,heatmap,gplots,R,Heatmap,Gplots,我使用gplots包的heatmap.2生成了一个热图: library(gplots) abc <-read.csv(file="abc.txt", header=T, sep="\t", dec=".") abcm<-as.matrix(abc) def <-read.csv(file="def.txt", header=T, sep="\t", dec=".") defm<-as.matrix(def) mean <-read.csv(file="mean.t

我使用gplots包的heatmap.2生成了一个热图:

library(gplots)
abc <-read.csv(file="abc.txt", header=T, sep="\t", dec=".")
abcm<-as.matrix(abc)
def <-read.csv(file="def.txt", header=T, sep="\t", dec=".")
defm<-as.matrix(def)
mean <-read.csv(file="mean.txt", header=T, sep="\t", dec=".")
meanm<-as.matrix(mean)
distance.row = dist(as.matrix(def), method = "euclidean")
cluster.row = hclust(distance.row, method = "average")
distance.col = dist(t(as.matrix(abc)), method = "euclidean")
cluster.col = hclust(distance.col, method = "average")
my_palette <- colorRampPalette(c("red", "yellow", "green"))(n = 299)

heatmap.2(meanm, trace="none", dendrogram="both", Rowv=as.dendrogram(cluster.row), Colv=as.dendrogram(cluster.col), margins = c(7,7), col=my_palette)

函数
重新排序。树状图
翻转分支

reorder(as.dendrogram(cluster.col), 10:1)
reorder(as.dendrogram(cluster.row), 10:1)
用于

heatmap.2(meanm, trace="none", dendrogram="both",
Rowv=reorder(as.dendrogram(cluster.row), 10:1),
Colv=reorder(as.dendrogram(cluster.col), 10:1),
margins = c(7,7), breaks=breaks,col=hm.colors, na.color="white",
main="mean(AAI+ANI)", xlab="AAI clustering", ylab="ANI clustering", srtCol=45)

你能包括样本数据吗?最简单的方法可能是对数据的子集使用
dput()
。@LukeC查看我的编辑!谢谢@rororo-我认为为了完整起见,您需要包括
cluster.row
cluster.col
,这样用户就可以像您一样绘制热图了。然而,我可能误解了你的意思——你想重新排列你的行和列,这样你就可以得到一个对角线。这不会破坏你的树状图吗?对于sp 4、1、8和3,这不一定重要(只需翻转该分支),但对于sp 9、6和7,我看不到允许对角线的树状图配置。有关更多信息,请参见
heatmap.2
Rowv
Colv
参数。如果我不理解你,我道歉!哦,我完全忽略了这一点!sp9的聚类方式有所不同:/但是,我如何翻转分支,使至少大多数项对齐?也许可以尝试
重新排序。树状图
-查看该函数帮助中的示例,它似乎可以满足您的需要。
heatmap.2(meanm, trace="none", dendrogram="both",
Rowv=reorder(as.dendrogram(cluster.row), 10:1),
Colv=reorder(as.dendrogram(cluster.col), 10:1),
margins = c(7,7), breaks=breaks,col=hm.colors, na.color="white",
main="mean(AAI+ANI)", xlab="AAI clustering", ylab="ANI clustering", srtCol=45)