So this should work:

library(phytools)
set.seed(42)
tree<-pbtree(n=10)
tree$tip.label<-c("A","B","Q","M","C","D","F","X","Z","W")
color<-rep("black",length(tree$tip.label))
color[which(tree$tip.label=="A")]<-"red"
edgecolor<-rep("black",length(tree$edge))
ind = which(tree$tip.label=="A") #
edgecolor[match(ind, tree$edge[,2])]<-"red"
plot(tree, edge.color=edgecolor)

Regards,
Klaus

On Tue, Jan 26, 2016 at 7:03 AM, Gygli, Gudrun <gudrun.gy...@wur.nl> wrote:

> Dear Klaus,
>
> Dear phylo-R users,
>
>
> your code does work but is still not doing exactly what I want.
>
>
> I am hoping to get the number of the edge which leads to A automatically
> through sth similar to what I have for the colouring of the tips.
>
> (color[which(tree$tip.label=="A")]<-"red")
>
>
>
> Also, I would like to colour the other branches (from earlier "split-off-
> nodes") leading to A in red too.
>
>
> Let me try to clarify:
>
> I work on creating a tree for a protein family and want to colour branches
> based on a selection of protein names
>
> (by creating a vector which contains all the names of proteins which share
> properties),
>
> (for example using sth like this
> color[which(tree$tip.label%in%VECTORWITHNAMES)]<-"red")
>
>  and these proteins cluster in the same part of the tree, thus I want to
> colour all the branches leading to these protein-tips red (or any other
> colour).
>
> To add some complexity, there are different properties that different
> proteins in that tree share, so in the end I would like to have different
> colours in the tree, with each colour reflecting another property...
>
>
> Any ideas if this is possible in R or with another tool?
>
>
> Thanks for the help
>
>
> G
>
>
> Gudrun Gygli, MSc
>
> PhD candidate
>
> Wageningen University
> Laboratory of Biochemistry
> Dreijenlaan 3
> 6703 HA Wageningen
> The Netherlands
>
> Phone  31 317483387
> e-mail: gudrun.gy...@wur.nl
>
> - - - - - - - - - - - - - - - - - -
>
> Project information:
> http://www.wageningenur.nl/en/show/Bioinformatics-structural-biology-and-molecular-modeling-of-Vanillyl-Alcohol-Oxidases-VAOs.htm
> ________________________________
> From: Klaus Schliep <klaus.schl...@gmail.com>
> Sent: Tuesday, January 26, 2016 10:34 AM
> To: Gygli, Gudrun
> Cc: r-sig-phylo@r-project.org
> Subject: Re: [R-sig-phylo] colouring tree branches like tips
>
> Dear Gudrun,
>
> almost right, try this code:
> set.seed(42)
> tree<-pbtree(n=10)
> tree$tip.label<-c("A","B","Q","M","C","D","F","X","Z","W")
> color<-rep("black",length(tree$tip.label))
> color[which(tree$tip.label=="A")]<-"red"
> edgecolor<-rep("black",length(tree$edge))
> plot(tree)
> edgelabels()
> # edge 3 leads to A
> edgecolor[3]<-"red"
> plot(tree, edge.color=edgecolor)
>
> Regards,
> Klaus
>
>
> On Tue, Jan 26, 2016 at 3:06 AM, Gygli, Gudrun <gudrun.gy...@wur.nl
> <mailto:gudrun.gy...@wur.nl>> wrote:
> Dear fellow phylo-R users,
>
>
> I am trying to colour tree (terminal and non terminal) branches in the
> same colour as the tip of said branch.
>
>
> To illustrate, see the code below, which is almost doing what I want. You
> can see that only colouring a specific tip, which is called A in this
> example, is no problem.
>
>
> However, I cannot colour the branches leading up to tip "A" in red with
> this code. I tried using tree$edge, but this is not working the way I
> thought.
>
>
> Does anyone know how to colour all the branches leading up to tip "A" in
> red?
>
>
> tree<-pbtree(n=10)
> tree$tip.label<-c("A","B","Q","M","C","D","F","X","Z","W")
> color<-rep("black",length(tree$tip.label))
> color[which(tree$tip.label=="A")]<-"red"
> edgecolor<-rep("black",length(tree$edge))
> edgecolor[which(tree$tip.label=="A")]<-"red"
>
>
> Thanks a lot for any help.
>
>
> Best regards
>
>
> G
>
>
>
> Gudrun Gygli, MSc
>
> PhD candidate
>
> Wageningen University
> Laboratory of Biochemistry
> Dreijenlaan 3
> 6703 HA Wageningen
> The Netherlands
>
> Phone  31 317483387
> e-mail: gudrun.gy...@wur.nl<mailto:gudrun.gy...@wur.nl>
>
> - - - - - - - - - - - - - - - - - -
>
> Project information:
> http://www.wageningenur.nl/en/show/Bioinformatics-structural-biology-and-molecular-modeling-of-Vanillyl-Alcohol-Oxidases-VAOs.htm
>
> _______________________________________________
> R-sig-phylo mailing list - R-sig-phylo@r-project.org<mailto:
> R-sig-phylo@r-project.org>
> https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
> Searchable archive at
> http://www.mail-archive.com/r-sig-phylo@r-project.org/
>
>
>
> --
> Klaus Schliep
> Postdoctoral Fellow
> Revell Lab, University of Massachusetts Boston
>
>


-- 
Klaus Schliep
Postdoctoral Fellow
Revell Lab, University of Massachusetts Boston

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/

Reply via email to