Browse code

fortify method works with missing value of edge length

git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/ggtree@116634 bc3139a8-67e5-0310-9ffc-ced21a209358

g.yu authored on 21/04/2016 06:05:17
Showing 4 changed files

... ...
@@ -1,7 +1,7 @@
1 1
 Package: ggtree
2 2
 Type: Package
3 3
 Title: a phylogenetic tree viewer for different types of tree annotations
4
-Version: 1.3.15
4
+Version: 1.3.16
5 5
 Author: Guangchuang Yu and Tommy Tsan-Yuk Lam
6 6
 Maintainer: Guangchuang Yu <guangchuangyu@gmail.com>
7 7
 Description: ggtree extends the ggplot2 plotting system which implemented the
... ...
@@ -1,3 +1,8 @@
1
+CHANGES IN VERSION 1.3.16
2
+------------------------
3
+ o update fortify.phylo to work with phylo that has missing value of edge length <2016-04-21, Thu>
4
+   + https://github.com/GuangchuangYu/ggtree/issues/54
5
+ 
1 6
 CHANGES IN VERSION 1.3.15
2 7
 ------------------------
3 8
  o geom_tiplab2 supports parameter hjust <2016-04-18, Mon>
... ...
@@ -16,7 +16,7 @@ read.nhx <- function(file) {
16 16
     }
17 17
     treetext %<>% gsub(" ", "",. )
18 18
     
19
-    phylo <- read.tree(file)
19
+    phylo <- read.tree(text=treetext)
20 20
     nnode <- phylo$Nnode + Ntip(phylo)
21 21
     nlab <- paste("X", 1:nnode, sep="")
22 22
     tree2 <- treetext
... ...
@@ -460,6 +460,13 @@ fortify.phylo <- function(model, data, layout="rectangular",
460 460
     } else {
461 461
         tree <- model
462 462
     }
463
+
464
+    if (! is.null(tree$edge.length)) {
465
+        if (any(is.na(tree$edge.length))) {
466
+            warning("'edge.length' contains NA values...\n## setting 'edge.length' to NULL automatically when plotting the tree...")
467
+            tree$edge.length <- NULL
468
+        }
469
+    }
463 470
     
464 471
     df <- as.data.frame(tree, layout=layout, ...)
465 472
     idx <- is.na(df$parent)
... ...
@@ -525,6 +532,7 @@ as.data.frame.phylo_ <- function(x, layout="rectangular",
525 532
     
526 533
     edge <- as.data.frame(x[["edge"]])
527 534
     colnames(edge) <- c("parent", "node")
535
+    
528 536
     if (! is.null(x$edge.length)) {
529 537
         edge$length <- x$edge.length
530 538
         if (branch.length == "none") {