0

I knew that I can set tip color by grouping the tip labels like this:

library(ggtree)
tree<-read.tree(text="(A,(B,C));"
dd <-data.frame(taxa=c("A","B","C"),place=c("s1","s1","s2"))
p<-ggtree(tree)
p<-p %<+% dd +geom_tiplab(aes(color=place))
p

So that random sets of color are applied according to the place group
But how do I specify my own color? (for example I want s1 in black and s2 in red)

Cai Bian
  • 141
  • 1
  • 6
  • 1
    You could make a new column with the exact colors you want, e.g. `data.frame(... , mycols = "green","red","blue")`, then in the aestethic you use `color = mycols`. A better way is to use `scale_colour_manual()` – mhovd Sep 09 '20 at 08:46

1 Answers1

2

You can set the tip color by using groupOTU on the tree and the branches.

tree<-read.tree(text="(A,(B,C));")
branches <- list(A=1,B=2,C=3)
tree <- groupOTU(tree,branches)

p <- ggtree(tree) + geom_tiplab(aes(color=group))+
  scale_color_manual(values=c(A = "#E7B800",B= "#FC4E07", C = "darkgreen"))
p

enter image description here

Phylo
  • 46
  • 2