Browse code

Merge pull request #525 from xiangpin/master

update fortify for pvclust

Guangchuang Yu authored on 15/08/2022 09:47:48 • GitHub committed on 15/08/2022 09:47:48
Showing 3 changed files

... ...
@@ -120,7 +120,6 @@ revts <- function(treeview) {
120 120
     mx <- max(x, na.rm=TRUE)
121 121
     treeview$data$x <- x - mx
122 122
     treeview$data$branch <- treeview$data$branch - mx
123
-	tip.edge.len <- attr(treeview$data, 'tip.edge.len')
124 123
     treeview
125 124
 }
126 125
 
... ...
@@ -32,6 +32,18 @@ scaleY <- function(phylo, df, yscale, layout, ...) {
32 32
 }
33 33
 
34 34
 
35
+adjust_hclust_tip.edge.len <- function(df, phylo){
36
+    mx <- max(df$x, na.rm=TRUE)
37
+    df$x <- df$x - mx       
38
+    df$branch <- df$branch - mx
39
+    tip.edge.len <- attr(phylo, 'tip.edge.len')
40
+    if (!is.null(tip.edge.len)){
41
+        df[df$isTip, "x", drop=TRUE] <- tip.edge.len
42
+    }                       
43
+    attr(df, 'revts.done') = TRUE
44
+    return(df)
45
+}
46
+
35 47
 ##
36 48
 ##
37 49
 ## old version of fortify.phylo
... ...
@@ -148,14 +148,7 @@ fortify.phylo4 <- function(model, data,
148 148
 
149 149
     df <- fortify.phylo(phylo, data,
150 150
                         layout, ladderize, right, mrsd=mrsd, ...)
151
-    mx <- max(df$x, na.rm=TRUE)
152
-    df$x <- df$x - mx
153
-    df$branch <- df$branch - mx
154
-    tip.edge.len <- attr(phylo, 'tip.edge.len')
155
-    if (!is.null(tip.edge.len)){
156
-        df[df$isTip, "x", drop=TRUE] <- tip.edge.len
157
-    }
158
-    attr(df, 'revts.done') = TRUE
151
+    df <- adjust_hclust_tip.edge.len(df, phylo)
159 152
     scaleY(phylo, df, yscale, layout, ...)
160 153
 }
161 154
 
... ...
@@ -205,8 +198,12 @@ fortify.phylo4d <- function(model, data,
205 198
                             right         = FALSE,
206 199
                             branch.length = "branch.length",
207 200
                             mrsd          = NULL,
201
+							hang          = 0.1,
208 202
                             ...) {
209
-    fortify(as.treedata(model), data, layout, yscale, ladderize, right, branch.length, mrsd, ...)
203
+    model <- as.treedata(model, hang = hang)
204
+    df <- fortify(model, data, layout, yscale, ladderize, right, branch.length, mrsd, ...)
205
+    df <- adjust_hclust_tip.edge.len(df, model@phylo)
206
+    return (df)
210 207
 }
211 208
 
212 209
 ##' @method fortify pvclust