Today, we are doing genetic Clustering Analysis and have encountered unexpected situations.
Library ('gplots') mydist = function (x) {dist (x, method = 'euclidean ')} myclust = function (y) {hclust (Y, method = 'ward ')} mycol = greenred (24) Hm = heatmap.2 (exp_data_diff_max_probes, scale = 'row', distfun = mydist, hclustfun = myclust, trace = 'none ', col = mycol) However, when comparing the clustering tree chart in the heat map (HM) with the tree Chart drawn by the function, we find that it is not the same! Plot (. hclust (HM $ coldendrogram) plot (colclust <-myclust (mydist (T (exp_data_diff_max_probes) Find the source code, and finally find that the tree sequence in the heat map function has a step more: reorder colv = colmeans (exp_data_diff_max_probes, Na. rm = T) DDC = reorder (. dendrogram (colclust), colv) colind = order. dendrogram (DDC) colind # The reordered cluster has the same order of heatmap
The role of reorder is described in the help document of R: "a dendrogram where each node has a further attribute value with its corresponding weight. "" There're using different orderings of a dendrogram that are consistent with the structure imposed. this function takes a dendrogram and a vector of values and reorders the dendrogram in the order of the supplied vector, maintaining the constraints on the dendrogram. "Indeed, reorder does not change the tree The clusters in the graph only reorder the elements in the clusters and clusters!
In the help document of reorder, type in the example codes:
require(graphics)set.seed(123)x <- rnorm(10)hc <- hclust(dist(x))dd <- as.dendrogram(hc)dd.reorder <- reorder(dd, 10:1)op <- par(mfrow = c(1,3))plot(dd, main = "random dendrogram 'dd'")plot(dd.reorder, main = "reorder(dd, 10:1)")plot(reorder(dd, 10:1, agglo.FUN = mean), main = "reorder(dd, 10:1, mean)")par(op)