Browse code

Merge pull request #527 from xiangpin/master

To better support the visualization of pvclust class using ggtree

Guangchuang Yu authored on 19/08/2022 07:37:44 • GitHub committed on 19/08/2022 07:37:44
Showing2 changed files

... ...
@@ -33,7 +33,11 @@ scaleY <- function(phylo, df, yscale, layout, ...) {
33 33
 
34 34
 
35 35
 adjust_hclust_tip.edge.len <- function(df, phylo){
36
-    tip.edge.len <- attr(phylo, 'tip.edge.len')
36
+    if (inherits(phylo, 'treedata')){
37
+        tip.edge.len <- attr(phylo@phylo, 'tip.edge.len')
38
+    }else{
39
+        tip.edge.len <- attr(phylo, 'tip.edge.len')
40
+    }
37 41
     if (!is.null(tip.edge.len)){
38 42
         mx <- max(df$x, na.rm=TRUE)
39 43
         df$x <- df$x - mx
... ...
@@ -68,6 +68,7 @@ fortify.phylo <- function(model, data,
68 68
         res <- calculate_angle(res)
69 69
     }
70 70
     res <- scaleY(as.phylo(model), res, yscale, layout, ...)
71
+    res <- adjust_hclust_tip.edge.len(res, x)
71 72
     class(res) <- c("tbl_tree", class(res))
72 73
     attr(res, "layout") <- layout
73 74
     return(res)
... ...
@@ -148,7 +149,6 @@ fortify.phylo4 <- function(model, data,
148 149
 
149 150
     df <- fortify.phylo(phylo, data,
150 151
                         layout, ladderize, right, mrsd=mrsd, ...)
151
-    df <- adjust_hclust_tip.edge.len(df, phylo)
152 152
     scaleY(phylo, df, yscale, layout, ...)
153 153
 }
154 154
 
... ...
@@ -202,7 +202,6 @@ fortify.phylo4d <- function(model, data,
202 202
                             ...) {
203 203
     model <- as.treedata(model, hang = hang)
204 204
     df <- fortify(model, data, layout, yscale, ladderize, right, branch.length, mrsd, ...)
205
-    df <- adjust_hclust_tip.edge.len(df, model@phylo)
206 205
     return (df)
207 206
 }
208 207