Search code examples
rphylogeny

Drawing points in phylogenetic tree R


I would like to draw only one point on the fist node, and then draw another one in the first tip. So far I could draw points but only all of them at once and I cannot find the way to draw it separately. What I have so far:

library(ape)
t3 = '((a:1,b:1):1,(c:1.5,d:0.5):0.5):1;'
plot(read.tree(text = t3),root.edge=T)
nodelabels(pch=21, col="black", adj=1, bg='blue', cex=2) 

any help is appreciated


Solution

  • This isn't the exact answer, but it should help. I got this by looking at the code for nodelabels function.

    library(ape)
    t3 = '((a:1,b:1):1,(c:1.5,d:0.5):0.5):1;'
    plot(read.tree(text = t3),root.edge=T)
    
    lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv)
    node <- (lastPP$Ntip + 1):length(lastPP$xx)
    XX <- lastPP$xx[node]
    YY <- lastPP$yy[node]
    BOTHlabels(text="", node, XX[1], YY[1], adj = c(0.5, 0.5), 
    frame = "rect", pch = 21, thermo = NULL, pie = NULL, 
    piecol = NULL, col = "blue", bg = "blue", 
    horiz = FALSE, width = NULL, height = NULL, cex=2)
    

    The XX's and YY's gives the nodes. Here, I'm using only the first one. What you have to do for tips is similar, too. Have a look at the code for tiplabels.