我想用 reorder.dendrogram 重新排序一个树状图,但不能弯曲我的头关于如何设置参数。
树状图有一个“异常值”分支,我想将其移至另一侧。
我可以通过这个 cut/merge 调用来做到这一点,但肯定可以通过重新排序来实现吗?
这是树状图:
tdro <- structure(list(structure(9L, members = 1L, height = 0, label = "leaf1", leaf = TRUE, class = "dendrogram"),
structure(list(structure(list(structure(list(structure(list(
structure(15L, label = "leaf2", members = 1L, height = 0, leaf = TRUE, class = "dendrogram"),
structure(14L, label = "leaf3", members = 1L, height = 0, leaf = TRUE, class = "dendrogram")), members = 2L, midpoint = 0.5, height = 24.8381484584436, class = "dendrogram"),
structure(list(structure(13L, label = "leaf4", members = 1L, height = 0, leaf = TRUE, class = "dendrogram"),
structure(12L, label = "leaf5", members = 1L, height = 0, leaf = TRUE, class = "dendrogram")), members = 2L, midpoint = 0.5, height = 24.3975287023022, class = "dendrogram")), members = 4L, midpoint = 1.5, height = 33.1101361501252, class = "dendrogram"),
structure(list(structure(10L, members = 1L, height = 0, label = "leaf6", leaf = TRUE, class = "dendrogram"),
structure(list(structure(11L, label = "leaf7", members = 1L, height = 0, leaf = TRUE, class = "dendrogram"),
structure(8L, label = "leaf8", members = 1L, height = 0, leaf = TRUE, class = "dendrogram")), members = 2L, midpoint = 0.5, height = 30.9363490461899, class = "dendrogram")), members = 3L, midpoint = 0.75, height = 32.3912839969328, class = "dendrogram")), members = 7L, midpoint = 3.125, height = 36.9011152635297, class = "dendrogram"),
structure(list(structure(5L, members = 1L, height = 0, label = "leaf9", leaf = TRUE, class = "dendrogram"),
structure(list(structure(list(structure(4L, members = 1L, height = 0, label = "leaf10", leaf = TRUE, class = "dendrogram"),
structure(list(structure(2L, label = "leaf11", members = 1L, height = 0, leaf = TRUE, class = "dendrogram"),
structure(6L, label = "leaf12", members = 1L, height = 0, leaf = TRUE, class = "dendrogram")), members = 2L, midpoint = 0.5, height = 20.537001267289, class = "dendrogram")), members = 3L, midpoint = 0.75, height = 27.9153607968991, class = "dendrogram"),
structure(list(structure(list(structure(7L, label = "leaf13", members = 1L, height = 0, leaf = TRUE, class = "dendrogram"),
structure(3L, label = "leaf14", members = 1L, height = 0, leaf = TRUE, class = "dendrogram")), members = 2L, midpoint = 0.5, height = 19.3278637150999, class = "dendrogram"),
structure(1L, members = 1L, height = 0, label = "leaf15", leaf = TRUE, class = "dendrogram")), members = 3L, midpoint = 1.25, height = 27.6624008548179, class = "dendrogram")), members = 6L, midpoint = 2.5, height = 30.8706298846279, class = "dendrogram")), members = 7L, midpoint = 1.75, height = 41.426993488228, class = "dendrogram")), members = 14L, midpoint = 5.9375, height = 41.7600747862578, class = "dendrogram")), members = 15L, midpoint = 3.46875, height = 66.2893195420674, class = "dendrogram")
plot(tdro)
这是我所追求的:
ddr_cut <- cut(tdro, 50)
want_tdro <- merge(ddr_cut$lower[[2]],
ddr_cut$lower[[1]],
height=attr(ddr_cut$upper, "height"))
plot(want_tdro)
问题是,下面的调用应该是怎样的:
plot(reorder(tdro, c(15,1:14)))
这样就变成了want_tdro
?为什么?_