library(ape)
library(Biostrings)
library(ggplot2)
library(ggtree)
library(tibble)
library(tidyr)
library(treeio)
####Set your wd
setwd("Working_Directory")
#####Load in tree data and make sure that it loads correctly
nex <- ("RAxML_bipartitionsBranchLabels.all_4_85")
tree <- read.raxml(nex)
tree
# Show tree information
tree@phylo$tip.label
tree@data$bootstrap
####Make major groupings for clade labeling
smallgroups <- list(
"Northern Deep Alaska"=c("Alaska_28", "Alaska_13"),
"Large Pacific 1"=c("PacificNW_15")
)
###Root the tree (if needed)
roottree <- root.phylo(tree, "Dlighti_7", resolve.root=TRUE)
###Assign groups to the tree
grouptree <- groupOTU(tree, smallgroups)
###Make a data frame with these groups to rename the tips
name_4_85 <- c("Alaska_Nome", "Alaska_Bering Sea", "Alaska_Nome", "Diadumene lighti")
d <- data.frame(label=grouptree@phylo$tip.label, tipnames=name_4_85)
###Plot the tree
p <- ggtree(grouptree, ladderize =T, right=F, aes(color=group)) %<+% d +
geom_tiplab(aes(label=tipnames), offset = 0, size=2.5, color = "black", hjust = 0) +
geom_text2(aes(label=bootstrap, subset=bootstrap>70), size=3, color = "black", hjust = 1, vjust = -0.3) +
scale_color_manual(values=c('black', '#91cf60'),
breaks=c("Northern Deep Alaska", "Large Pacific 1")) +
labs(color = "Geographic Groups") +
theme(plot.margin = unit(c(1,1,1.5,1.2), "cm")) +
theme(legend.position = "right") +
ggplot2::xlim(0,0.05)
p
###Show internal node labels to assign clade labels to
p + geom_text(aes(label=node), hjust=-.3)