Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206305

Function to add singleton (near tip) in one step

$
0
0

Is there any function to do that in one step? I am applying a two-step workaround

{
require(grid)
require(phytools)
require(ggtree)
set.seed(10)
tree <- rtree(7)

myggtreeplot <- ggtree(tree) + geom_nodepoint() + geom_tiplab() + geom_treescale()

edge=data.frame(parent=tree$edge[,1], node=tree$edge[,2], other=NA,stringsAsFactors = F)

# tree with node names
myggtreeplot %<+% edge + geom_label(aes(x=branch, label=node)) + geom_treescale()

# 1st step: add tip
tree2 <- bind.tip(tree, "new tip", edge.length= 0.5, where= 3, position=0.5)
ggtree(tree2) + geom_nodepoint() + geom_tiplab() + geom_treescale()

# 2nd step: remove to obtain singleton
tree3 <- drop.tip(tree2, "new_tip", collapse.singles = FALSE) # ape

# identify number of node
newtreeplot <- ggtree(tree3) + geom_nodepoint() + geom_tiplab() 
edge=data.frame(parent=tree2$edge[,1], node=tree2$edge[,2], other=NA,stringsAsFactors = F)
newtreeplot %<+% edge + geom_label(aes(x=branch, label=node)) 

{
grid.newpage()
pushViewport(viewport(layout = grid.layout(1, 2)))
pushViewport(viewport(layout.pos.col = 1, layout.pos.row = 1))
print(myggtreeplot,newpage=F) 
popViewport()
pushViewport(viewport(layout.pos.col = 2, layout.pos.row = 1))
print( (newtreeplot + geom_point2(aes(subset=(node==11)), shape=21, size=5, fill='green') + geom_treescale() ), 
       newpage = F )
}
}

enter image description here


Viewing all articles
Browse latest Browse all 206305

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>