Browse code

as.phylo.hclust2

Guangchuang Yu authored on 21/06/2022 08:59:44
Showing4 changed files

... ...
@@ -1,7 +1,7 @@
1 1
 Package: ggtree
2 2
 Type: Package
3 3
 Title: an R package for visualization of tree and annotation data
4
-Version: 3.5.0.902
4
+Version: 3.5.1
5 5
 Authors@R: c(
6 6
        person("Guangchuang", "Yu",     email = "guangchuangyu@gmail.com", role = c("aut", "cre", "cph"), 
7 7
             comment = c(ORCID = "0000-0002-6485-8781")),
... ...
@@ -25,10 +25,10 @@
25 25
 
26 26
 -->
27 27
 
28
-# ggtree 3.5.0.902
28
+# ggtree 3.5.1
29 29
 
30
++ `as.phylo.hclust2` to correct edge length as displayed in `stats:::plot.hclust` (2022-06-21, Tue)
30 31
 + add outline to nodepies (2022-06-20, Mon, #506)
31
-+ `update_edge_hclust()` to adjust edge length of a `phylo` object converted from a `hclust` object via `ape::as.phylo()` (2022-06-05, Sun)
32 32
 + new 'slanted' layout for `branch.length = 'none'` (2022-04-29, Fri, #497)
33 33
     - only works for Cartesian coordination, that means it will not work for `layout = 'radial'`
34 34
 
... ...
@@ -134,12 +134,16 @@ fortify.phylo4 <- function(model, data,
134 134
                            right     = FALSE,
135 135
                            mrsd      = NULL,
136 136
                            ...) {
137
-    if (class(model) %in% c("dendrogram", "agnes", "diana", "twins")) {
137
+    if (inherits(model, c("dendrogram", "agnes", "diana", "twins"))) {
138 138
         model <- stats::as.hclust(model)
139 139
     }
140 140
 
141
-    
142
-    phylo <- as.phylo(model)
141
+    if (inherits(model, "hclust")) {
142
+        phylo <- as.phylo.hclust2(model)
143
+    } else {
144
+        phylo <- as.phylo(model)
145
+    }
146
+
143 147
     df <- fortify.phylo(phylo, data,
144 148
                         layout, ladderize, right, mrsd=mrsd, ...)
145 149
     scaleY(phylo, df, yscale, layout, ...)
... ...
@@ -1319,8 +1319,10 @@ edge2vec <- function(tr) {
1319 1319
 }
1320 1320
 
1321 1321
 
1322
-# tr is converted from h via ape::as.phylo
1323
-update_edge_hclust <- function(tr, h) {
1322
+
1323
+as.phylo.hclust2 <- function(x, hang=0.1, ...) {
1324
+  h <- x
1325
+  tr <- ape::as.phylo(x)
1324 1326
   ev <- edge2vec(tr)
1325 1327
 
1326 1328
   #extract_inode_hclust_item <- function(h, i, ev) {
... ...
@@ -1354,7 +1356,7 @@ update_edge_hclust <- function(tr, h) {
1354 1356
   pn <- ev[nodes]
1355 1357
   pn[pn == 0] <- treeio::rootnode(tr)
1356 1358
   len[nodes] <- len[pn] - len[nodes]
1357
-  len[1:Ntip(tr)] <- max(h$height)/10
1359
+  len[1:Ntip(tr)] <- hang #max(h$height)/10
1358 1360
 
1359 1361
   tr$edge.length <- len[tr$edge[,2]]
1360 1362
   return(tr)