I have been trying to plot a tree with color-coded branches and tips using the ggtree
package in R. Here is an example code using a tree of Anolis lizards.
library(ggtree);library(tidyverse);library(ape)
anole.tree<-read.tree("http://www.phytools.org/eqg2015/data/anole.tre")
svl <- read.csv("http://www.phytools.org/eqg2015/data/svl.csv",row.names=1)
cls<-list(clade1=c("baleatus","barahonae","ricordii","eugenegrahami","christophei","cuvieri"),
clade2=subset(anole.tree$tip.label,!(anole.tree$tip.label %in% c("baleatus","barahonae","ricordii","eugenegrahami","christophei","cuveri"))))
anole.tree_new<-groupOTU(anole.tree,.node=cls)
ggtree(anole.tree_new,layout="circular",ladderize=TRUE)+
geom_tree(aes(color=group))+
scale_color_manual(values=c("blue","red"))+
geom_tiplab(size=0.8,aes(color=group))+
theme(legend.position = c(0.9, 1),
legend.justification = c(0,1),
legend.title=element_text(size=7),legend.text=element_text(size=7))
The issue I am having with this is that the resulting plot includes a text element (a small "a") as part of the legend. I have been unable to figure out how to omit this text element from the legend. I want to keep the legend itself but I don't want the red and blue "a" that are plotted alongside the red and blue lines in the above example.
Normally it would be as simple as not setting the color argument to be an aes within the element labels (geom_tiplab). However, if I do not call group color under aes...
ggtree(anole.tree_new,layout="circular",ladderize=TRUE)+
geom_tree(aes(color=group))+
scale_color_manual(values=c("blue","red"))+
geom_tiplab(size=0.8,color=group)+
theme(legend.position = c(0.9, 1),
legend.justification = c(0,1),
legend.title=element_text(size=7),legend.text=element_text(size=7))
I get an error saying object "group" not found. So it doesn't seem to be as straightforward as in a normal ggplot.
guide = FALSE
option inscale_color_manual
will remove it from legend. – Sinh Nguyen