@@ -183,11 +183,15 @@ print.phyloLayout <- function(obj) {
183
183
pd $ nodes $ y [tips ] <- 1 : Ntip(phy )
184
184
185
185
# assign vertical positions to internal nodes
186
- internals <- pd $ edges $ child [! pd $ edges $ isTip ]
187
- for (i in rev(internals )) {
188
- children <- pd $ edges $ child [pd $ edges $ parent == i ]
189
- pd $ nodes $ y [i ] <- mean(pd $ nodes $ y [children ])
186
+ max.n.tips <- max(pd $ nodes $ n.tips )
187
+ for (i in 1 : max.n.tips ) {
188
+ internals <- which(pd $ nodes $ n.tips == i )
189
+ for (j in internals ) {
190
+ children <- pd $ edges $ child [pd $ edges $ parent == j ]
191
+ pd $ nodes $ y [j ] <- mean(pd $ nodes $ y [children ])
192
+ }
190
193
}
194
+
191
195
root <- Ntip(phy )+ 1
192
196
children <- pd $ edges $ child [pd $ edges $ parent == root ]
193
197
pd $ nodes $ y [root ] <- mean(pd $ nodes $ y [children ])
@@ -230,11 +234,15 @@ print.phyloLayout <- function(obj) {
230
234
pd $ nodes $ angle [tips ] <- (1 : Ntip(phy )) / Ntip(phy ) * 2 * pi
231
235
232
236
# assign angles to internal nodes
233
- internals <- pd $ edges $ child [! pd $ edges $ isTip ]
234
- for (i in rev(internals )) {
235
- children <- pd $ edges $ child [pd $ edges $ parent == i ]
236
- pd $ nodes $ angle [i ] <- mean(pd $ nodes $ angle [children ])
237
+ max.n.tips <- max(pd $ nodes $ n.tips )
238
+ for (i in 1 : max.n.tips ) {
239
+ internals <- which(pd $ nodes $ n.tips == i )
240
+ for (j in internals ) {
241
+ children <- pd $ edges $ child [pd $ edges $ parent == j ]
242
+ pd $ nodes $ angle [j ] <- mean(pd $ nodes $ angle [children ])
243
+ }
237
244
}
245
+
238
246
root <- Ntip(phy )+ 1
239
247
children <- pd $ edges $ child [pd $ edges $ parent == root ]
240
248
pd $ nodes $ angle [root ] <- mean(pd $ nodes $ angle [children ])
0 commit comments