Skip to content

Commit 8d865e6

Browse files
committed
fixes #15
1 parent dc271f5 commit 8d865e6

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

R/tree.R

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,15 @@ print.phyloLayout <- function(obj) {
183183
pd$nodes$y[tips] <- 1:Ntip(phy)
184184

185185
# 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+
}
190193
}
194+
191195
root <- Ntip(phy)+1
192196
children <- pd$edges$child[pd$edges$parent==root]
193197
pd$nodes$y[root] <- mean(pd$nodes$y[children])
@@ -230,11 +234,15 @@ print.phyloLayout <- function(obj) {
230234
pd$nodes$angle[tips] <- (1:Ntip(phy)) / Ntip(phy) * 2 * pi
231235

232236
# 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+
}
237244
}
245+
238246
root <- Ntip(phy)+1
239247
children <- pd$edges$child[pd$edges$parent==root]
240248
pd$nodes$angle[root] <- mean(pd$nodes$angle[children])

0 commit comments

Comments
 (0)