简体   繁体   中英

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

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 .

You can define to which node you want to plot with the "node" argument within the nodelabels function, and the same is true for tiplabels function but with "tip" argument. So:

library(ape)
t3 = '((a:1,b:1):1,(c:1.5,d:0.5):0.5):1;'
tree <- read.tree(text = t3)
first_node <- length(tree$tip.label)+1
plot(tree, root.edge=T)
nodelabels(node = first_node, pch=21, col="black", bg='blue', cex=2)
tiplabels(tip = 1, pch=21, col="black", bg='blue', cex=2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM