简体   繁体   中英

Node labels on circular phylogenetic tree

I am trying to create circular phylogenetic tree. I have this part of code:

fit<- hclust(dist(Data[,-4]), method = "complete", members = NULL)

nclus= 3
color=c('red','blue','green')
color_list=rep(color,nclus/length(color))
clus=cutree(fit,nclus)

plot(as.phylo(fit),type='fan',tip.color=color_list[clus],label.offset=0.2,no.margin=TRUE, cex=0.70, show.node.label = TRUE)

And this is result: 在此输入图像描述

Also I am trying to show label for each node and to color branches. Any suggestion how to do that?

Thanks!

When you say "color branches" I assume you mean color the edges. This seems to work, but I have to think there's a better way.

Using the built-in mtcars dataset here, since you did not provide your data.

plot.fan <- function(hc, nclus=3) {
  palette <- c('red','blue','green','orange','black')[1:nclus]
  clus    <-cutree(hc,nclus)
  X <- as.phylo(hc)
  edge.clus <- sapply(1:nclus,function(i)max(which(X$edge[,2] %in% which(clus==i))))
  order     <- order(edge.clus)
  edge.clus <- c(min(edge.clus),diff(sort(edge.clus)))
  edge.clus <- rep(order,edge.clus)
  plot(X,type='fan',
       tip.color=palette[clus],edge.color=palette[edge.clus],
       label.offset=0.2,no.margin=TRUE, cex=0.70)  
}
fit <- hclust(dist(mtcars[,c("mpg","hp","wt","disp")]))
plot.fan(fit,3); plot.fan(fit,5)

Regarding "label the nodes", if you mean label the tips, it looks like you've already done that. If you want different labels, unfortunately, unlike plot.hclust(...) the labels=... argument is rejected. You could experiment with the tiplabels(....) function, but it does not seem to work very well with type="fan" . The labels come from the row names of Data , so your best bet IMO is to change the row names prior to clustering.

If you actually mean label the nodes (the connection points between the edges, have a look at nodelabels(...) . I don't provide a working example because I can't imagine what labels you would put there.

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