@@ -1003,26 +1003,36 @@ draw.branch <- function(layout, tips, col='red', ...) {
1003
1003
# ' @param tips: a character vector of tip labels
1004
1004
# '
1005
1005
# ' @export
1006
- draw.clade <- function (layout , tips , col = ' red' , ... ) {
1007
- unmatched <- ! is.element(tips , layout $ nodes $ label )
1006
+ draw.clade <- function (obj , tips , col = ' red' , ... ) {
1007
+ unmatched <- ! is.element(tips , obj $ nodes $ label )
1008
1008
if (any(unmatched )) {
1009
1009
stop(" Error: not all tip labels found in tree layout:" )
1010
1010
cat(tips [! unmatched ])
1011
1011
}
1012
1012
1013
1013
# find most recent common ancestor
1014
- idx <- sapply(tips , function (l ) which(layout $ nodes $ label == l ))
1015
- traj <- lapply(idx , function (i ) .climb.tree(i , edges ))
1014
+ idx <- sapply(tips , function (l ) which(obj $ nodes $ label == l ))
1015
+ traj <- lapply(idx , function (i ) .climb.tree(i , obj $ edges ))
1016
1016
common <- Reduce(intersect , traj )
1017
1017
if (length(common ) < 1 ) {
1018
1018
stop(" Error: Failed to locate common ancestor of tips " , tips )
1019
1019
}
1020
1020
1021
1021
clade <- setdiff(Reduce(union , traj ), common )
1022
- e <- layout $ edges [is.element(layout $ edges $ child , clade ), ]
1023
- segments(e $ x0 , e $ y0 , e $ x1 , e $ y1 , col , ... )
1024
-
1025
- # do tips as well
1026
- e <- layout $ edges [is.element(layout $ edges $ child , idx ), ]
1022
+ e <- obj $ edges [is.element(obj $ edges $ child , c(idx , clade )), ]
1027
1023
segments(e $ x0 , e $ y0 , e $ x1 , e $ y1 , col , ... )
1024
+
1025
+ if (obj $ layout == ' rectangular' ) {
1026
+ parents <- sapply(e $ parent , function (p ) which(obj $ edges $ child == p ))
1027
+ segments(x0 = e $ x0 , y0 = e $ y0 , y1 = obj $ edges $ y0 [parents ], col = col , ... )
1028
+ }
1029
+ else if (obj $ layout == ' radial' ) {
1030
+ nodes <- obj $ nodes [e $ child ,]
1031
+ parents <- sapply(e $ parent , function (p ) which(obj $ edges $ child == p ))
1032
+ pnodes <- obj $ nodes [obj $ edges $ child [parents ],]
1033
+ for (i in 1 : nrow(nodes )) {
1034
+ draw.arc(x = 0 , y = 0 , theta0 = nodes $ angle [i ], theta1 = pnodes $ angle [i ],
1035
+ r0 = pnodes $ r [i ], col = col , ... )
1036
+ }
1037
+ }
1028
1038
}
0 commit comments