raphiinae_list <- "115"
raphiinae_subtending_list <- "115"
stiriinae_list <- clade.members(stiriinae_node,tree,tip.labels=TRUE)
tyta_copibryophila_list <- clade.members(tyta_copibryophila_node,tree,tip.labels=TRUE)
#Noctuinae is paraphyletic with respect to Eriopinae and Bryphilinae. The below code will remove Eriopinae and Bryophilinae taxa from Noctuinae, which will allow
#to color them separately
non_noctuinae=c(clade.members(bryophilinae_node,tree,tip.labels=TRUE),clade.members(eriopinae_node,tree,tip.labels=TRUE))
noctuinae_list=setdiff(clade.members(noctuinae_node,tree,tip.labels=TRUE),non_noctuinae)
#Defome groups in the tree which will be used for coloring purposes. For some reason adding a node (e.g. homolagoa_subtending) works here, but replacing the lists of clade members with their
#most recent common ancestor node results in them not being colored.
tree <- groupOTU(tree,list(acontiinae_list,acronictinae_list,agaristinae_list,amphipyrinae_list,aucha_list,bagisarinae_list,
balsinae_list,balsinae_node,bryophilinae_list,condicinae_list,cropiinae_list,cuculliinae_list,dilobinae_list,dilobinae_subtending_list,
dilobinae_node,dyopsinae_list,eriopinae_list,eustrotiinae_list,
grotellinae_list,heliothinae_list,homolagoa_list,metoponiinae_list,noctuinae_list,
oncocnemidinae_list,pantheinae_list,plusiinae_list,pseudeustrotiini_list,raphiinae_list,raphiinae_node,
stiriinae_list,tyta_copibryophila_list), group_name="subfamily_OTU")
#Color-blind friendly colors from https://personal.sron.nl/~pault/#sec:qualitative
blue <- "#4477AA"
cyan <- "#66CCEE"
grey <- "#BBBBBB"
red <- "red"
black <- "black"
#Define color palette to be used for coloring groups in the tree.
subfamily_palette <- c(black,blue,grey,blue,cyan,cyan,grey,cyan,blue,grey,
grey,cyan,blue,cyan,cyan,blue,grey,blue,grey,
cyan,grey,cyan,grey,cyan,blue,cyan,blue)
# Compose the tree ---------------------------------------------------------------------------------------------------------  -----------
tree <- ggtree(tree, layout="rectangular", right = TRUE, branch.length="true", size=.6,aes(color=subfamily_OTU))
# tree <- ggtree::collapse(tree,489,mode='min')
tree <- tree %<+% info +
scale_colour_manual(values=subfamily_palette) +
geom_label(data=sig_labels,aes(label=label), size = 2, label.padding=unit(0.1, "lines"), color="black", fill="white") +
geom_tiplab(aes(label=paste(Code_original,Genus,Species,sep = " ")),size=02.5, fontface='italic') +
geom_cladelabel(outgroups, label="Notodontidae,\nEutelliidae,\nErebidae,\n& Nolidae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.3, offset.text = 0.03, color='black') +
geom_cladelabel(noctuinae_node, label="Noctuinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(amphipyrinae_node, label="Amphipyrinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(bryophilinae_node, label="Bryophilini", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
geom_cladelabel(nacopa_clade_node, label="Nacopa clade", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
geom_cladelabel(pseudeustrotiini_node, label="Pseudeustrotiini & Condicinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(grotellinae_node, label="Grotellinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(acontiinae_node, label="Acontiinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(oncocnemidinae_node, label="Oncocnemidinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(stiriinae_node, label="Stiriinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(plusiinae_node, label="Plusiinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(metoponiinae_node, label="Metoponiinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(aucha_node, label="Aucha, Cobubatha,\n& Tripudia", angle = 0, barsize = 0.6, fontface = "bold.italic", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(heliothinae_node, label="Heliothinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(acronictinae_node, label="Acronictinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(cropiinae_node, label="Cropiinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(bagisarinae_node, label="Bagisarinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(eustrotiinae_node, label="Eustrotiinae", angle = 0, abarsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(pantheinae_node, label="Pantheinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(balsinae_node, label="Balsinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(raphiinae_node, label="Raphiinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(dilobinae_node, label="Dilobinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(cuculliinae_node, label="Cuculliinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(dyopsinae_node, label="Dyopsinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(agaristinae_node, label="Agaristinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(eriopinae_node, label="Eriopini", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
geom_cladelabel(homolagoa_node, label="Homolagoa", angle = 0, barsize = 0.6, fontface = "bold.italic", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(tyta_copibryophila_node, label="Aedia, Tyta,\n& Copibryphila", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(acontiini_node, label="Acontiini", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
geom_cladelabel(chamaecleini_node, label="Chamaecleini", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
xlim_tree(5)
tree <- tree + geom_treescale(x=0.3,y=1.6,fontsize=4,linesize=.4,offset = 0.1)
#plot(tree)
ggsave(tree,file="tree_image.pdf", device="pdf", units = "cm", width=58, height=150, limitsize = FALSE, dpi=600)
dev.off()
library("ggtree")
library("treeio")
library("phytools")#for findMRCA
library("caper") #for clade.members
library("ggplot2")
# Input/Output ---------------------------------------------------------------------------------------------------------------------
#Read in tree file
tree <- read.tree("RAxML_bipartitions.all_taxa")
#Grab data for bootstrap values now and store them in a dataframe.
q <- ggtree(tree, layout="rectangular", right = TRUE, branch.length="true")
d <- q$data
d <- d[!d$isTip,]
d <- d[!d$label=="Root",]
sig_labels <- d[as.double(d$label) > 0,]
#Read in additional data about taxa we will use later (like in labeling tips)
info <- read.csv("Noctuidae_26_voucher_table.csv")
#Get node numbers for clades to color/label.
outgroups <- findMRCA(tree,c("MM00107","MM01048"))
acontiinae_node <- findMRCA(tree,c("MM00152","KLKDNA0363"))
acronictinae_node <- findMRCA(tree,c("DLW79","DLW123"))
agaristinae_node <- findMRCA(tree,c("MM07669","AM_93_0448"))
amphipyrinae_node <- findMRCA(tree,c("KLKDNA0023","KLKDNA0050"))
aucha_node <- findMRCA(tree,c("AZ023_42cmb","KLKDNA0421"))
bagisarinae_node <- findMRCA(tree,c("RZ621","RZ50"))
balsinae_node <- findMRCA(tree,c("DLW77","DLW76"))
bryophilinae_node <- findMRCA(tree,c("RZ523", "KLKDNA0389"))
condicinae_node <- findMRCA(tree,c("OUT_LSU20","RZ341"))
cropiinae_node <- findMRCA(tree,c("KLKDNA0034","KLKDNA0193"))
cuculliinae_node <- findMRCA(tree,c("MM04543","KLKDNA0231"))
dilobinae_node <- nodeid(tree,"MM09267")
dilobinae_subtending <- findMRCA(tree,c("MM09267","MM09267"))
dyopsinae_node <- findMRCA(tree,c("RZ384","RZ10"))
eriopinae_node <- findMRCA(tree,c("KLKDNA0247","CFIA_LEP3214"))
eustrotiinae_node <- findMRCA(tree,c("CFIA_LEP3201","CFIA_LEP3218"))
grotellinae_node <- findMRCA(tree,c("KLKDNA0038","KLKDNA0434"))
heliothinae_node <- findMRCA(tree,c("AM_GB_045","AM_GB_016"))
homolagoa_node <- nodeid(tree,"KLKDNA0301")
metoponiinae_node <- findMRCA(tree,c("KLKDNA0039","KLKDNA0171"))
noctuinae_node <- findMRCA(tree,c("SMK023","AM_GB_021"))
oncocnemidinae_node <- findMRCA(tree,c("KLKDNA0401","KLKDNA0033"))
pantheinae_node <- findMRCA(tree,c("DLW82","AM_GB_032"))
plusiinae_node <- findMRCA(tree,c("MM02752","MM05132"))
plusiinae_subtending <- findMRCA(tree,c("MM02752","MM05132"))
pseudeustrotiini_node <- findMRCA(tree,c("CWM_93_0001","CFIA_LEP3217"))
raphiinae_node <- nodeid(tree,"CWM_94_0372")
raphiinae_subtending <- findMRCA(tree,c("CWM_94_0372","CWM_94_0372"))
stiriinae_node <- findMRCA(tree,c("KLKDNA0003","KLKDNA0324"))
tyta_copibryophila_node <- findMRCA(tree,c("KLKDNA0335","KLKDNA0350"))
acontiini_node <- findMRCA(tree,c("MM00152","AM_GB_193"))
chamaecleini_node <- findMRCA(tree,c("AM_GB_007","KLKDNA0406"))
nacopa_clade_node <- findMRCA(tree,c("KLKDNA0151","KLKDNA0340"))
#Get lists of tip labels to use later in grouping taxa for coloring purposes
acontiinae_list <- clade.members(acontiinae_node,tree,tip.labels=TRUE)
acronictinae_list <- clade.members(acronictinae_node,tree,tip.labels=TRUE)
agaristinae_list <- clade.members(agaristinae_node,tree,tip.labels=TRUE)
amphipyrinae_list <- clade.members(amphipyrinae_node,tree,tip.labels=TRUE)
aucha_list <- clade.members(aucha_node,tree,tip.labels=TRUE)
bagisarinae_list <- clade.members(bagisarinae_node,tree,tip.labels=TRUE)
balsinae_list <- clade.members(balsinae_node,tree,tip.labels=TRUE)
bryophilinae_list <- clade.members(bryophilinae_node,tree,tip.labels=TRUE)
condicinae_list <- clade.members(condicinae_node,tree,tip.labels=TRUE)
cropiinae_list <- clade.members(cropiinae_node,tree,tip.labels=TRUE)
cuculliinae_list <- clade.members(cuculliinae_node,tree,tip.labels=TRUE)
dilobinae_list <- clade.members(dilobinae_node,tree,tip.labels=TRUE)
dilobinae_subtending_list <- clade.members(dilobinae_subtending,tree,tip.labels=TRUE)
dyopsinae_list <- clade.members(dyopsinae_node,tree,tip.labels=TRUE)
eriopinae_list <- clade.members(eriopinae_node,tree,tip.labels=TRUE)
eustrotiinae_list <- clade.members(eustrotiinae_node,tree,tip.labels=TRUE)
grotellinae_list <- clade.members(grotellinae_node,tree,tip.labels=TRUE)
heliothinae_list <- clade.members(heliothinae_node,tree,tip.labels=TRUE)
homolagoa_list <- clade.members(homolagoa_node,tree,tip.labels=TRUE)
metoponiinae_list <- clade.members(metoponiinae_node,tree,tip.labels=TRUE)
noctuinae_list <- clade.members(noctuinae_node,tree,tip.labels=TRUE)
oncocnemidinae_list <- clade.members(oncocnemidinae_node,tree,tip.labels=TRUE)
pantheinae_list <- clade.members(pantheinae_node,tree,tip.labels=TRUE)
plusiinae_list <- clade.members(plusiinae_node,tree,tip.labels=TRUE)
plusiinae_subtending_list <- clade.members(plusiinae_subtending,tree,tip.labels = TRUE)
pseudeustrotiini_list <- clade.members(pseudeustrotiini_node,tree,tip.labels=TRUE)
raphiinae_list <- "115"
raphiinae_subtending_list <- "115"
stiriinae_list <- clade.members(stiriinae_node,tree,tip.labels=TRUE)
tyta_copibryophila_list <- clade.members(tyta_copibryophila_node,tree,tip.labels=TRUE)
#Noctuinae is paraphyletic with respect to Eriopinae and Bryphilinae. The below code will remove Eriopinae and Bryophilinae taxa from Noctuinae, which will allow
#to color them separately
non_noctuinae=c(clade.members(bryophilinae_node,tree,tip.labels=TRUE),clade.members(eriopinae_node,tree,tip.labels=TRUE))
noctuinae_list=setdiff(clade.members(noctuinae_node,tree,tip.labels=TRUE),non_noctuinae)
#Defome groups in the tree which will be used for coloring purposes. For some reason adding a node (e.g. homolagoa_subtending) works here, but replacing the lists of clade members with their
#most recent common ancestor node results in them not being colored.
tree <- groupOTU(tree,list(acontiinae_list,acronictinae_list,agaristinae_list,amphipyrinae_list,aucha_list,bagisarinae_list,
balsinae_list,balsinae_node,bryophilinae_list,condicinae_list,cropiinae_list,cuculliinae_list,dilobinae_list,dilobinae_subtending_list,
dilobinae_node,dyopsinae_list,eriopinae_list,eustrotiinae_list,
grotellinae_list,heliothinae_list,homolagoa_list,metoponiinae_list,noctuinae_list,
oncocnemidinae_list,pantheinae_list,plusiinae_list,pseudeustrotiini_list,raphiinae_list,raphiinae_node,
stiriinae_list,tyta_copibryophila_list), group_name="subfamily_OTU")
#Color-blind friendly colors from https://personal.sron.nl/~pault/#sec:qualitative
blue <- "#4477AA"
cyan <- "#66CCEE"
grey <- "#BBBBBB"
red <- "red"
black <- "black"
#Define color palette to be used for coloring groups in the tree.
subfamily_palette <- c(black,blue,grey,blue,cyan,cyan,grey,cyan,blue,grey,
grey,cyan,blue,cyan,cyan,blue,grey,blue,grey,
cyan,grey,cyan,grey,cyan,blue,cyan,blue)
# Compose the tree ---------------------------------------------------------------------------------------------------------  -----------
tree <- ggtree(tree, layout="rectangular", right = TRUE, branch.length="true", size=.6,aes(color=subfamily_OTU))
# tree <- ggtree::collapse(tree,489,mode='min')
tree <- tree %<+% info +
scale_colour_manual(values=subfamily_palette) +
geom_label(data=sig_labels,aes(label=label), size = 2, label.padding=unit(0.1, "lines"), color="black", fill="white") +
geom_tiplab(aes(label=paste(Code_original,Genus,Species,sep = " ")),size=02.5, fontface='italic') +
geom_cladelabel(outgroups, label="Notodontidae,\nEutelliidae,\nErebidae,\n& Nolidae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.32, offset.text = 0.03, color='black') +
geom_cladelabel(noctuinae_node, label="Noctuinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(amphipyrinae_node, label="Amphipyrinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(bryophilinae_node, label="Bryophilini", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
geom_cladelabel(nacopa_clade_node, label="Nacopa clade", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
geom_cladelabel(pseudeustrotiini_node, label="Pseudeustrotiini & Condicinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(grotellinae_node, label="Grotellinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(acontiinae_node, label="Acontiinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(oncocnemidinae_node, label="Oncocnemidinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(stiriinae_node, label="Stiriinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(plusiinae_node, label="Plusiinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(metoponiinae_node, label="Metoponiinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(aucha_node, label="Aucha, Cobubatha,\n& Tripudia", angle = 0, barsize = 0.6, fontface = "bold.italic", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(heliothinae_node, label="Heliothinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(acronictinae_node, label="Acronictinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(cropiinae_node, label="Cropiinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(bagisarinae_node, label="Bagisarinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(eustrotiinae_node, label="Eustrotiinae", angle = 0, abarsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(pantheinae_node, label="Pantheinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(balsinae_node, label="Balsinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(raphiinae_node, label="Raphiinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(dilobinae_node, label="Dilobinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(cuculliinae_node, label="Cuculliinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(dyopsinae_node, label="Dyopsinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(agaristinae_node, label="Agaristinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(eriopinae_node, label="Eriopini", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
geom_cladelabel(homolagoa_node, label="Homolagoa", angle = 0, barsize = 0.6, fontface = "bold.italic", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(tyta_copibryophila_node, label="Aedia, Tyta,\n& Copibryphila", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(acontiini_node, label="Acontiini", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
geom_cladelabel(chamaecleini_node, label="Chamaecleini", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
xlim_tree(5)
tree <- tree + geom_treescale(x=0.3,y=1.6,fontsize=4,linesize=.4,offset = 0.1)
#plot(tree)
ggsave(tree,file="tree_image.pdf", device="pdf", units = "cm", width=58, height=150, limitsize = FALSE, dpi=600)
dev.off()
library("ggtree")
library("treeio")
library("phytools")#for findMRCA
library("caper") #for clade.members
library("ggplot2")
# Input/Output ---------------------------------------------------------------------------------------------------------------------
#Read in tree file
tree <- read.tree("RAxML_bipartitions.all_taxa")
#Grab data for bootstrap values now and store them in a dataframe.
q <- ggtree(tree, layout="rectangular", right = TRUE, branch.length="true")
d <- q$data
d <- d[!d$isTip,]
d <- d[!d$label=="Root",]
sig_labels <- d[as.double(d$label) > 0,]
#Read in additional data about taxa we will use later (like in labeling tips)
info <- read.csv("Noctuidae_26_voucher_table.csv")
#Get node numbers for clades to color/label.
outgroups <- findMRCA(tree,c("MM00107","MM01048"))
acontiinae_node <- findMRCA(tree,c("MM00152","KLKDNA0363"))
acronictinae_node <- findMRCA(tree,c("DLW79","DLW123"))
agaristinae_node <- findMRCA(tree,c("MM07669","AM_93_0448"))
amphipyrinae_node <- findMRCA(tree,c("KLKDNA0023","KLKDNA0050"))
aucha_node <- findMRCA(tree,c("AZ023_42cmb","KLKDNA0421"))
bagisarinae_node <- findMRCA(tree,c("RZ621","RZ50"))
balsinae_node <- findMRCA(tree,c("DLW77","DLW76"))
bryophilinae_node <- findMRCA(tree,c("RZ523", "KLKDNA0389"))
condicinae_node <- findMRCA(tree,c("OUT_LSU20","RZ341"))
cropiinae_node <- findMRCA(tree,c("KLKDNA0034","KLKDNA0193"))
cuculliinae_node <- findMRCA(tree,c("MM04543","KLKDNA0231"))
dilobinae_node <- nodeid(tree,"MM09267")
dilobinae_subtending <- findMRCA(tree,c("MM09267","MM09267"))
dyopsinae_node <- findMRCA(tree,c("RZ384","RZ10"))
eriopinae_node <- findMRCA(tree,c("KLKDNA0247","CFIA_LEP3214"))
eustrotiinae_node <- findMRCA(tree,c("CFIA_LEP3201","CFIA_LEP3218"))
grotellinae_node <- findMRCA(tree,c("KLKDNA0038","KLKDNA0434"))
heliothinae_node <- findMRCA(tree,c("AM_GB_045","AM_GB_016"))
homolagoa_node <- nodeid(tree,"KLKDNA0301")
metoponiinae_node <- findMRCA(tree,c("KLKDNA0039","KLKDNA0171"))
noctuinae_node <- findMRCA(tree,c("SMK023","AM_GB_021"))
oncocnemidinae_node <- findMRCA(tree,c("KLKDNA0401","KLKDNA0033"))
pantheinae_node <- findMRCA(tree,c("DLW82","AM_GB_032"))
plusiinae_node <- findMRCA(tree,c("MM02752","MM05132"))
plusiinae_subtending <- findMRCA(tree,c("MM02752","MM05132"))
pseudeustrotiini_node <- findMRCA(tree,c("CWM_93_0001","CFIA_LEP3217"))
raphiinae_node <- nodeid(tree,"CWM_94_0372")
raphiinae_subtending <- findMRCA(tree,c("CWM_94_0372","CWM_94_0372"))
stiriinae_node <- findMRCA(tree,c("KLKDNA0003","KLKDNA0324"))
tyta_copibryophila_node <- findMRCA(tree,c("KLKDNA0335","KLKDNA0350"))
acontiini_node <- findMRCA(tree,c("MM00152","AM_GB_193"))
chamaecleini_node <- findMRCA(tree,c("AM_GB_007","KLKDNA0406"))
nacopa_clade_node <- findMRCA(tree,c("KLKDNA0151","KLKDNA0340"))
phosphilini_node <- findMRCA(tree,c("CFIA_LEP3213","KLKDNA0185"))
#Get lists of tip labels to use later in grouping taxa for coloring purposes
acontiinae_list <- clade.members(acontiinae_node,tree,tip.labels=TRUE)
acronictinae_list <- clade.members(acronictinae_node,tree,tip.labels=TRUE)
agaristinae_list <- clade.members(agaristinae_node,tree,tip.labels=TRUE)
amphipyrinae_list <- clade.members(amphipyrinae_node,tree,tip.labels=TRUE)
aucha_list <- clade.members(aucha_node,tree,tip.labels=TRUE)
bagisarinae_list <- clade.members(bagisarinae_node,tree,tip.labels=TRUE)
balsinae_list <- clade.members(balsinae_node,tree,tip.labels=TRUE)
bryophilinae_list <- clade.members(bryophilinae_node,tree,tip.labels=TRUE)
condicinae_list <- clade.members(condicinae_node,tree,tip.labels=TRUE)
cropiinae_list <- clade.members(cropiinae_node,tree,tip.labels=TRUE)
cuculliinae_list <- clade.members(cuculliinae_node,tree,tip.labels=TRUE)
dilobinae_list <- clade.members(dilobinae_node,tree,tip.labels=TRUE)
dilobinae_subtending_list <- clade.members(dilobinae_subtending,tree,tip.labels=TRUE)
dyopsinae_list <- clade.members(dyopsinae_node,tree,tip.labels=TRUE)
eriopinae_list <- clade.members(eriopinae_node,tree,tip.labels=TRUE)
eustrotiinae_list <- clade.members(eustrotiinae_node,tree,tip.labels=TRUE)
grotellinae_list <- clade.members(grotellinae_node,tree,tip.labels=TRUE)
heliothinae_list <- clade.members(heliothinae_node,tree,tip.labels=TRUE)
homolagoa_list <- clade.members(homolagoa_node,tree,tip.labels=TRUE)
metoponiinae_list <- clade.members(metoponiinae_node,tree,tip.labels=TRUE)
noctuinae_list <- clade.members(noctuinae_node,tree,tip.labels=TRUE)
oncocnemidinae_list <- clade.members(oncocnemidinae_node,tree,tip.labels=TRUE)
pantheinae_list <- clade.members(pantheinae_node,tree,tip.labels=TRUE)
plusiinae_list <- clade.members(plusiinae_node,tree,tip.labels=TRUE)
plusiinae_subtending_list <- clade.members(plusiinae_subtending,tree,tip.labels = TRUE)
pseudeustrotiini_list <- clade.members(pseudeustrotiini_node,tree,tip.labels=TRUE)
raphiinae_list <- "115"
raphiinae_subtending_list <- "115"
stiriinae_list <- clade.members(stiriinae_node,tree,tip.labels=TRUE)
tyta_copibryophila_list <- clade.members(tyta_copibryophila_node,tree,tip.labels=TRUE)
#Noctuinae is paraphyletic with respect to Eriopinae and Bryphilinae. The below code will remove Eriopinae and Bryophilinae taxa from Noctuinae, which will allow
#to color them separately
non_noctuinae=c(clade.members(bryophilinae_node,tree,tip.labels=TRUE),clade.members(eriopinae_node,tree,tip.labels=TRUE))
noctuinae_list=setdiff(clade.members(noctuinae_node,tree,tip.labels=TRUE),non_noctuinae)
#Defome groups in the tree which will be used for coloring purposes. For some reason adding a node (e.g. homolagoa_subtending) works here, but replacing the lists of clade members with their
#most recent common ancestor node results in them not being colored.
tree <- groupOTU(tree,list(acontiinae_list,acronictinae_list,agaristinae_list,amphipyrinae_list,aucha_list,bagisarinae_list,
balsinae_list,balsinae_node,bryophilinae_list,condicinae_list,cropiinae_list,cuculliinae_list,dilobinae_list,dilobinae_subtending_list,
dilobinae_node,dyopsinae_list,eriopinae_list,eustrotiinae_list,
grotellinae_list,heliothinae_list,homolagoa_list,metoponiinae_list,noctuinae_list,
oncocnemidinae_list,pantheinae_list,plusiinae_list,pseudeustrotiini_list,raphiinae_list,raphiinae_node,
stiriinae_list,tyta_copibryophila_list), group_name="subfamily_OTU")
#Color-blind friendly colors from https://personal.sron.nl/~pault/#sec:qualitative
blue <- "#4477AA"
cyan <- "#66CCEE"
grey <- "#BBBBBB"
red <- "red"
black <- "black"
#Define color palette to be used for coloring groups in the tree.
subfamily_palette <- c(black,blue,grey,blue,cyan,cyan,grey,cyan,blue,grey,
grey,cyan,blue,cyan,cyan,blue,grey,blue,grey,
cyan,grey,cyan,grey,cyan,blue,cyan,blue)
# Compose the tree ---------------------------------------------------------------------------------------------------------  -----------
tree <- ggtree(tree, layout="rectangular", right = TRUE, branch.length="true", size=.6,aes(color=subfamily_OTU))
# tree <- ggtree::collapse(tree,489,mode='min')
tree <- tree %<+% info +
scale_colour_manual(values=subfamily_palette) +
geom_label(data=sig_labels,aes(label=label), size = 2, label.padding=unit(0.1, "lines"), color="black", fill="white") +
geom_tiplab(aes(label=paste(Code_original,Genus,Species,sep = " ")),size=02.5, fontface='italic') +
geom_cladelabel(outgroups, label="Notodontidae,\nEutelliidae,\nErebidae,\n& Nolidae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.32, offset.text = 0.03, color='black') +
geom_cladelabel(noctuinae_node, label="Noctuinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(amphipyrinae_node, label="Amphipyrinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(bryophilinae_node, label="Bryophilini", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
geom_cladelabel(phosphilini_node, label="Phosphilini", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
geom_cladelabel(nacopa_clade_node, label="Nacopa clade", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
geom_cladelabel(pseudeustrotiini_node, label="Pseudeustrotiini & Condicinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(grotellinae_node, label="Grotellinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(acontiinae_node, label="Acontiinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(oncocnemidinae_node, label="Oncocnemidinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(stiriinae_node, label="Stiriinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(plusiinae_node, label="Plusiinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(metoponiinae_node, label="Metoponiinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(aucha_node, label="Aucha, Cobubatha,\n& Tripudia", angle = 0, barsize = 0.6, fontface = "bold.italic", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(heliothinae_node, label="Heliothinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(acronictinae_node, label="Acronictinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(cropiinae_node, label="Cropiinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(bagisarinae_node, label="Bagisarinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(eustrotiinae_node, label="Eustrotiinae", angle = 0, abarsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(pantheinae_node, label="Pantheinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(balsinae_node, label="Balsinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(raphiinae_node, label="Raphiinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(dilobinae_node, label="Dilobinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(cuculliinae_node, label="Cuculliinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(dyopsinae_node, label="Dyopsinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(agaristinae_node, label="Agaristinae", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(eriopinae_node, label="Eriopini", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
geom_cladelabel(homolagoa_node, label="Homolagoa", angle = 0, barsize = 0.6, fontface = "bold.italic", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(tyta_copibryophila_node, label="Aedia, Tyta,\n& Copibryphila", angle = 0, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0, offset = 0.25, offset.text = 0.03, color='black') +
geom_cladelabel(acontiini_node, label="Acontiini", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
geom_cladelabel(chamaecleini_node, label="Chamaecleini", angle = -90, barsize = 0.6, fontface = "bold", fontsize=4, align = TRUE, hjust = 0.5, offset = 0.17, offset.text = 0.03, color='black') +
xlim_tree(5)
tree <- tree + geom_treescale(x=0.3,y=1.6,fontsize=4,linesize=.4,offset = 0.1)
#plot(tree)
ggsave(tree,file="tree_image.pdf", device="pdf", units = "cm", width=58, height=150, limitsize = FALSE, dpi=600)
setwd("~/kevin.keegan@uconn.edu/Main_Storage/Documents/Graduate_School/Manuscripts/Noctuidae/Current_Draft/For_Data_Dryad/IQ-TREE_all_taxa")
library("ggtree")
library("treeio")
library("phytools")#for findMRCA
library("caper") #for clade.members
tree <- read.tree("output.treefile")
#################################################################################################
#Converts tree object from class "phy" to "phylo". Not doing this will cause error with findMRCA function.
tree <- as.phylo(tree)
tree <- root(tree, "MM09888")
#Read in additional data about taxa we will use later (like in labeling tips)
info <- read.csv("Noctuidae_26_voucher_table.csv")
### Create a Dataframe for Node Labels we Want to Show ###
q <- ggtree(tree, layout="rectangular", right = TRUE, branch.length="true",aes(color=black, linetype="solid"))
d <- q$data
d <- d[!d$isTip,]
d <- d[!d$label=="Root",]
#sig_labels <- which(lapply(strsplit(d$label, split='/', fixed=TRUE), `[`, 1) >= 80 & lapply(strsplit(d$label, split='/', fixed=TRUE), `[`, 3) >= 95)
tree <- ggtree(tree, layout = 'rectangular', right = TRUE, size = .04)
tree <- tree %<+% info +
geom_tiplab(aes(label=paste(Genus,Species,sep = " ")),size=1.2, fontface='italic', color="black")  +
geom_label(data=d, size=1.2, fill="white", color="black", aes(label=label), label.r=unit(0.001, "lines"), label.size=.01, label.padding=unit(0.03, "lines")) +
xlim_tree(0)
tree <- tree + geom_treescale(x=0.3,y=1.6,fontsize=1,linesize=.04,offset = 0.5)
ggsave(tree,file="tree_Noctuidae_26_IQTREE.pdf", device="pdf", units = "in", width=8.5, height=22, limitsize = FALSE, dpi=500)
dev.off()
library("ggtree")
library("treeio")
library("phytools")#for findMRCA
library("caper") #for clade.members
tree <- read.tree("output.treefile")
#################################################################################################
#Converts tree object from class "phy" to "phylo". Not doing this will cause error with findMRCA function.
tree <- as.phylo(tree)
tree <- root(tree, "MM09888")
#Read in additional data about taxa we will use later (like in labeling tips)
info <- read.csv("Noctuidae_26_voucher_table.csv")
### Create a Dataframe for Node Labels we Want to Show ###
q <- ggtree(tree, layout="rectangular", right = TRUE, branch.length="true",aes(color=black, linetype="solid"))
d <- q$data
d <- d[!d$isTip,]
d <- d[!d$label=="Root",]
#sig_labels <- which(lapply(strsplit(d$label, split='/', fixed=TRUE), `[`, 1) >= 80 & lapply(strsplit(d$label, split='/', fixed=TRUE), `[`, 3) >= 95)
tree <- ggtree(tree, layout = 'rectangular', right = TRUE, size = .04)
tree <- tree %<+% info +
geom_tiplab(aes(label=paste(Genus,Species,sep = " ")),size=1.2, fontface='italic', color="black")  +
geom_label(data=d, size=1.2, fill="white", color="black", aes(label=label), label.r=unit(0.001, "lines"), label.size=.01, label.padding=unit(0.03, "lines")) +
xlim_tree(0)
tree <- tree + geom_treescale(x=0.3,y=1.6,fontsize=1,linesize=.04,offset = 0.5)
ggsave(tree,file="tree_Noctuidae_26_IQTREE.pdf", device="pdf", units = "in", width=8.5, height=22, limitsize = FALSE, dpi=500)
dev.off()
library("ggtree")
library("treeio")
library("phytools")#for findMRCA
library("caper") #for clade.members
tree <- read.tree("output.treefile")
#################################################################################################
#Converts tree object from class "phy" to "phylo". Not doing this will cause error with findMRCA function.
tree <- as.phylo(tree)
tree <- root(tree, "MM09888")
#Read in additional data about taxa we will use later (like in labeling tips)
info <- read.csv("Noctuidae_26_voucher_table.csv")
### Create a Dataframe for Node Labels we Want to Show ###
q <- ggtree(tree, layout="rectangular", right = TRUE, branch.length="true",aes(color=black, linetype="solid"))
d <- q$data
d <- d[!d$isTip,]
d <- d[!d$label=="Root",]
#sig_labels <- which(lapply(strsplit(d$label, split='/', fixed=TRUE), `[`, 1) >= 80 & lapply(strsplit(d$label, split='/', fixed=TRUE), `[`, 3) >= 95)
tree <- ggtree(tree, layout = 'rectangular', right = TRUE, size = .04)
tree <- tree %<+% info +
geom_tiplab(aes(label=paste(Genus,Species,sep = " ")),size=1.2, fontface='italic', color="black")  +
geom_label(data=d, size=1.2, fill="white", color="black", aes(label=label), label.r=unit(0.001, "lines"), label.size=.01, label.padding=unit(0.03, "lines")) +
xlim_tree(0)
tree <- tree + geom_treescale(x=0.3,y=1.6,fontsize=1,linesize=.04,offset = 0.5)
ggsave(tree,file="tree_image.pdf", device="pdf", units = "in", width=8.5, height=22, limitsize = FALSE, dpi=500)
dev.off()
library("ggtree")
library("treeio")
library("phytools")#for findMRCA
library("caper") #for clade.members
tree <- read.tree("output.treefile")
#################################################################################################
#Converts tree object from class "phy" to "phylo". Not doing this will cause error with findMRCA function.
tree <- as.phylo(tree)
tree <- root(tree, "MM09888")
#Read in additional data about taxa we will use later (like in labeling tips)
info <- read.csv("Noctuidae_26_voucher_table.csv")
### Create a Dataframe for Node Labels we Want to Show ###
q <- ggtree(tree, layout="rectangular", right = TRUE, branch.length="true",aes(color=black, linetype="solid"))
d <- q$data
d <- d[!d$isTip,]
d <- d[!d$label=="Root",]
#sig_labels <- which(lapply(strsplit(d$label, split='/', fixed=TRUE), `[`, 1) >= 80 & lapply(strsplit(d$label, split='/', fixed=TRUE), `[`, 3) >= 95)
tree <- ggtree(tree, layout = 'rectangular', right = TRUE, size = .1)
tree <- tree %<+% info +
geom_tiplab(aes(label=paste(Genus,Species,sep = " ")),size=1.2, fontface='italic', color="black")  +
geom_label(data=d, size=1.2, fill="white", color="black", aes(label=label), label.r=unit(0.001, "lines"), label.size=.01, label.padding=unit(0.03, "lines")) +
xlim_tree(0)
tree <- tree + geom_treescale(x=0.3,y=1.6,fontsize=1,linesize=.04,offset = 0.5)
ggsave(tree,file="tree_image.pdf", device="pdf", units = "in", width=8.5, height=22, limitsize = FALSE, dpi=500)
dev.off()
library("ggtree")
library("treeio")
library("phytools")#for findMRCA
library("caper") #for clade.members
tree <- read.tree("output.treefile")
#################################################################################################
#Converts tree object from class "phy" to "phylo". Not doing this will cause error with findMRCA function.
tree <- as.phylo(tree)
tree <- root(tree, "MM09888")
#Read in additional data about taxa we will use later (like in labeling tips)
info <- read.csv("Noctuidae_26_voucher_table.csv")
### Create a Dataframe for Node Labels we Want to Show ###
q <- ggtree(tree, layout="rectangular", right = TRUE, branch.length="true",aes(color=black, linetype="solid"))
d <- q$data
d <- d[!d$isTip,]
d <- d[!d$label=="Root",]
#sig_labels <- which(lapply(strsplit(d$label, split='/', fixed=TRUE), `[`, 1) >= 80 & lapply(strsplit(d$label, split='/', fixed=TRUE), `[`, 3) >= 95)
tree <- ggtree(tree, layout = 'rectangular', right = TRUE, size = .5)
tree <- tree %<+% info +
geom_tiplab(aes(label=paste(Genus,Species,sep = " ")),size=1.2, fontface='italic', color="black")  +
geom_label(data=d, size=1.2, fill="white", color="black", aes(label=label), label.r=unit(0.001, "lines"), label.size=.01, label.padding=unit(0.03, "lines")) +
xlim_tree(0)
tree <- tree + geom_treescale(x=0.3,y=1.6,fontsize=1,linesize=.04,offset = 0.5)
ggsave(tree,file="tree_image.pdf", device="pdf", units = "in", width=8.5, height=22, limitsize = FALSE, dpi=500)
dev.off()
library("ggtree")
library("treeio")
library("phytools")#for findMRCA
library("caper") #for clade.members
tree <- read.tree("output.treefile")
#################################################################################################
#Converts tree object from class "phy" to "phylo". Not doing this will cause error with findMRCA function.
tree <- as.phylo(tree)
tree <- root(tree, "MM09888")
#Read in additional data about taxa we will use later (like in labeling tips)
info <- read.csv("Noctuidae_26_voucher_table.csv")
### Create a Dataframe for Node Labels we Want to Show ###
q <- ggtree(tree, layout="rectangular", right = TRUE, branch.length="true",aes(color=black, linetype="solid"))
d <- q$data
d <- d[!d$isTip,]
d <- d[!d$label=="Root",]
#sig_labels <- which(lapply(strsplit(d$label, split='/', fixed=TRUE), `[`, 1) >= 80 & lapply(strsplit(d$label, split='/', fixed=TRUE), `[`, 3) >= 95)
tree <- ggtree(tree, layout = 'rectangular', right = TRUE, size = .25)
tree <- tree %<+% info +
geom_tiplab(aes(label=paste(Genus,Species,sep = " ")),size=1.2, fontface='italic', color="black")  +
geom_label(data=d, size=1.2, fill="white", color="black", aes(label=label), label.r=unit(0.001, "lines"), label.size=.01, label.padding=unit(0.03, "lines")) +
xlim_tree(0)
tree <- tree + geom_treescale(x=0.3,y=1.6,fontsize=1,linesize=.04,offset = 0.5)
ggsave(tree,file="tree_image.pdf", device="pdf", units = "in", width=8.5, height=22, limitsize = FALSE, dpi=500)
dev.off()
