GGTree flips my trees
1
1
Entering edit mode
8 weeks ago
M. ▴ 40

Hi all,

I hope you are doing well. I am trying to visualize my phylogenetic tree with ggtree, but it keeps flipping my trees upside down. Below, you'll find a screenshot from Figtree and the ggtree output for the same tree. I circled the red clade from the Figtree in the ggtree output to help you better follow the topology. I tried flipping branches, rotating the tree, etc., but I couldn't manage to solve the problem. Is there any parameter to fix this? My code for ggtree is also provided below.

Can you help me with this issue? Thanks in advance.

p <- ggtree(tree, ladderize = FALSE, layout = "rectangular")

enter image description here enter image description here

R ggtree phylogenetics • 312 views
ADD COMMENT
3
Entering edit mode
8 weeks ago
Jesse ▴ 850

Funny, I just ran into exactly this problem myself recently. ggtree has its own rotate function but I couldn't figure out how to get it to work. Instead I made a wrapper around ape::rotate that seemed to do the trick:

rotate_all <- function(tree) {
  for (idx in seq(tree$Nnode + 2, nrow(tree$edge) + 1)) {
    tree <- ape::rotate(tree, idx)
  } 
  tree
}

(This implicitly assumes how nodes and edges are structured, with internal nodes getting higher numbers. That was just what seemed to be the case when I was playing around with it, but again, seemed to do the trick.)

ADD COMMENT
0
Entering edit mode

Thank you very much, Jesse! I've been struggling with this issue for a while. This function is a game-changer for me. Thanks!

ADD REPLY

Login before adding your answer.

Traffic: 1492 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6