diff --git a/.RData b/.RData index 36897f1..a25024f 100644 Binary files a/.RData and b/.RData differ diff --git a/.Rhistory b/.Rhistory index e69de29..f2686ee 100644 --- a/.Rhistory +++ b/.Rhistory @@ -0,0 +1,512 @@ +#select models with head mass +pgls_todo_hm<-pgls_todo_nogeomet[seq(2,length(pgls_todo_nogeomet),2)] +library(phytools) +library(ggalt) +library(ggrepel) +#get residuals from pgls of head mass vs each ear measure +source("Extract pgls residuals.R") +#Plotting adapted from: +#https://thackl.github.io/ggtree-composite-plots +library(patchwork) +library(viridis) +#color palettes +# The palette with grey: +cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7") +# The palette with black: +cbbPalette <- c( "#FFFFFF","#000000", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7") +barplot(1:5, col=cbbPalette) +#subset the df with resids dataframe to include only the residuals +#run the PCA scripts to create the dfwith resids data frame +names(dfwithresids) +#input column numbers that have residuals +residseach<-dfwithresids[,c(37:48)] +names(residseach) +#add +residseach$order<-dfwithresids$Order +residseach$Binomial<-dfwithresids$Binomial +residseach$Category<-dfwithresids$Category +residseach$divescore<-dfwithresids$divescore +residseach$plungedistinct<-dfwithresids$plungedistinct +residseach$waterbirds<-dfwithresids$waterbirds +residseach$superorder<-dfwithresids$superorder +residseach$IAC<-dfwithresids$IAC_detail +residseach$IBP<-dfwithresids$IBP_detail +residseach$PC1<-dfwithresids$PC1 +residseach$plungedistinct<-relevel(as.factor(residseach$plungedistinct),"Terrestrial") +#residseach$Category<-relevel(as.factor(residseach$Category),"Terrestrial") +#put in long format +longdfplotting<-gather(residseach,key = "earmeasuresresid", value = "earmeasureval", +-c(order,Binomial,Category,divescore,plungedistinct,IAC,IBP))#waterbirds,superorder, +longdfplotting$earmeasuresresid<-as.factor(longdfplotting$earmeasuresresid) +longdfplotting$earmeasureval<-as.numeric(longdfplotting$earmeasureval) +#longdfplotting$label<-longdfplotting$order +#longdfplotting$label<-longdfplotting$waterbirds +#longdfplotting$label<-longdfplotting$superorder +longdfplotting$label<-longdfplotting$order +longdfplotting$earmeasuresresid<-as.character(longdfplotting$earmeasuresresid) +longdfplotting$Terr<-longdfplotting$Category +longdfplotting$Terr<-ifelse(longdfplotting$Category=="Terrestrial","Terrestrial",NA) +#make list of ear measures to plot +yvarnames<-c( +"RES_logTMtotalarealogHeadmassg" , +"RES_logFPtotalarealogHeadmassg" , +"RES_logarearatiologHeadmassg" , +"RES_logdiscoltipTMcentroidlogHeadmassg" , +"RES_logUmbodistancetoTMplanelogHeadmassg", +"RES_logmeanTManglelogHeadmassg" , +"RES_logtotalEClengthlogHeadmassg" , +"RES_logRWtotalarealogHeadmassg" , +"RES_logCAtotalarealogHeadmassg" , +"RES_logBehindTMlogHeadmassg" , +"RES_logColumellalengthmmlogHeadmassg" , +"RES_logColumellavolumemm3logHeadmassg" ,"PC1") +#create functions for plotting +source("Tblog.R") +#add medians +#source("add median.R") +#############make the order-level cladogram for aligning the residuals########### +source("Order_level_cladogram.R") +### +ggtree(orderPhy)+ +geom_text(aes(label = node)) +gg_tr <- ggtree(orderPhy, branch.length = "none") + +geom_tiplab(align=TRUE) + +#scale_x_continuous(expand=expand_scale(0.2)) + # make more room for the labels +scale_y_tree()+ +xlim(0,40)+ +ylim(0.5,38)+ +annotate("text", x = 13,y = 36,label = "Terrestrial")+ +annotate("text", x = 13,y = 33.5,label = "Surface-foraging")+ +annotate("text", x = 13,y = 31,label = "Plunge-diving")+ +annotate("text", x = 13,y = 28.5,label = "Underwater-pursuit")+ +annotate("text", x = 1,y = 38,label = "A")+ +annotate("text", x = 1,y = 26,label = "B") +gg_tr +#reversed phylogenetic tree +gg_tr_rev <- ggtree(orderPhy, branch.length = "none", col = "white") + +geom_tiplab(align=TRUE) + +scale_x_continuous(expand=expand_scale(0.2)) + # make more room for the labels +scale_y_tree()+ +xlim(10,20)+ +ylim(0.5,38)+ +scale_x_reverse()+ +annotate("text", x = 11,y = 36,label = "Terrestrial")+ +annotate("text", x = 11,y = 33.5,label = "Surface-foraging")+ +annotate("text", x = 11,y = 31,label = "Plunge-diving")+ +annotate("text", x = 11,y = 28.5,label = "Underwater-pursuit") +gg_tr_rev +###############scatterplot function########### +gg_plungedistinct<-function(index2, letter, box = "yes"){ +ggtreeplot(gg_tr, subset(longdfplotting, +longdfplotting$earmeasuresresid==yvarnames[index2]), aes(y=earmeasureval), flip=TRUE) +{ +if(box == "yes") annotate("text",x = Inf, y = Inf, label = "*", hjust = 2, vjust = 1.25, size = 5) +else annotate("text",x = Inf, y = Inf, label = "", hjust = 2, vjust = 1.25) +} + +#geom_label(aes(x=Inf,y=-Inf,vjust = 1, +# hjust = -1,label=letter, lineheight = 0))+ +geom_vline(xintercept = 1:26,col = "black")+ +#geom_vline(xintercept = -4:30, col = "black")+ +#geom_rect(aes(xmin = -3.5, xmax = 26.5, ymin = -Inf, ymax = -Inf), col = "black", fill = "white", alpha = 0.1)+ +#geom_rect(aes(xmin = -3.5, xmax = 26.5, ymin = Inf, ymax = Inf), col = "black", fill = "white", alpha = 0.1)+ +#geom_line(aes(xmin = -3.5, xmax = 26.5, ymin = 0, ymax = 0), col = "black", size = 1)+ +geom_segment(aes(x = 0.5,xend = 38, y = 0, yend = 0), col = "black")+ +#geom_segment(aes(x = 28,xend = 36, y = 0, yend = 0), col = "black")+ +geom_point(aes(fill = plungedistinct), size = 3,shape = 21, col = "black")+ +scale_fill_manual(values = cbbPalette)+ +#geom_vline(xintercept = 27,col = "black")+ +coord_flip() + no_y_axis()+ +ylab("")+ +xlim(0.5,38)+ +theme_test() + +theme(axis.line.y = element_blank(), +axis.title.y = element_blank(), +axis.text.y = element_blank(), +axis.ticks.y = element_blank(), +#axis.text.x.left = element_text(), +axis.text.x = element_text(angle = 90, colour = "black"), +legend.position = "none", +plot.margin = margin(t = 5, r = 5, b = 0, l = 0, unit = "pt"))+ +geom_boxplot(data = subset(longdfplotting, +longdfplotting$earmeasuresresid==yvarnames[index2]& +longdfplotting$plungedistinct=="Terrestrial"), +aes(x = 36, y = earmeasureval),fill= "white", col = "black", outlier.size = 3, +outlier.colour = "black", width = 2.25, outlier.fill = "white", +outlier.shape = 21)+ +annotate("text",x = Inf, y = -Inf, label = letter,hjust = -1,vjust = 1.25, size = 5) +} +gg_plungedistinct(1, letter = "aa", box = "no") +gg_plungedistinct(1, letter = "aa", box = "yes") +annotate("text",x = Inf, y = -Inf, label = "a") +addbxplt(1,1,"a") +gg_plungedistinct(1, box = "no")+ +geom_text(aes(x=Inf,y=-Inf,vjust = 1, +hjust = -1,label="i")) +gg_plungedistinct(1, letter = "K", box = "yes") +gg_tr|addbxplt(1,1,"i") +############function to add boxplots at bottom################ +addbxplt<-function(j,index2,letter,box = "yes"){ +d<-gg_plungedistinct(index2,letter,box)+ +geom_boxplot(data = subset(longdfplotting, +longdfplotting$earmeasuresresid==yvarnames[j]& +longdfplotting$plungedistinct=="Plunging"), +aes(x = 31, y = earmeasureval),fill= "black",col = "black", outlier.size = 3, +outlier.fill = "#000000", outlier.shape = 21, width = 2.25, outlier.color = "black")+ +geom_boxplot(data = subset(longdfplotting, +longdfplotting$earmeasuresresid==yvarnames[j]& +longdfplotting$plungedistinct=="Underwater pursuit"), +aes(x = 28.5, y = earmeasureval),fill ="#56B4E9",col = "black", outlier.size = 3, +outlier.fill = "#56B4E9", outlier.shape = 21, width = 2.25, outlier.color = "black")+ +geom_boxplot(data = subset(longdfplotting, +longdfplotting$earmeasuresresid==yvarnames[j]& +longdfplotting$plungedistinct=="Surface"), +mapping = aes(x = 33.5, y = earmeasureval), fill = "#E69F00",col = "black", +outlier.size = 3, outlier.fill = "#E69F00", width = 2.25, outlier.shape = 21, outlier.color = "black") +d +} +#####################plots for interaural canal an interbullar passage####### +#data for plotting by order +summ2<-avgdf %>% group_by(Order,IBP_detail) %>% count(na.omit = T) +summ2$IBP_detail<-ifelse(summ2$IBP_detail=="Pneumaticity present"| +summ2$IBP_detail=="Pneumaticity absent"| +summ2$IBP_detail=="Y",summ2$IBP_detail,NA) +summ2$label<-summ2$Order +summ2$number<-summ2$n +summ2<-as.data.frame(summ2) +names(summ2) +summb<-summ2[which(!is.na(summ2$IBP_detail)),] +#data for plotting by ecology +summpl<-avgdf %>% group_by(IBP_detail,plungedistinct) %>% count(na.omit = T) +summpl$IBP_detail<-ifelse(summpl$IBP_detail=="Pneumaticity present"| +summpl$IBP_detail=="Pneumaticity absent"| +summpl$IBP_detail=="Y",summpl$IBP_detail,NA) +summpl$number<-summpl$n +summpl<-as.data.frame(summpl) +names(summpl) +summpl_<-summpl[which(!is.na(summpl$IBP_detail)),] +IBP<-function(letter){ +d<-ggtreeplot(gg_tr, summb, aes(y = number), flip=TRUE) + +geom_bar(aes(fill = as.factor(IBP_detail)), position = "fill", +color = "black",stat = "identity")+ +scale_fill_manual(values = c("black","grey","white"))+ +#no_legend()+ +xlim(0.5,38)+ +coord_flip() + no_y_axis()+ +theme(axis.text.x = element_text(angle = 90))+ +ylab("")+ +theme_test() + +theme(axis.line.y = element_blank(), +axis.title.y = element_blank(), +axis.text.y = element_blank(), +axis.ticks.y = element_blank(), +axis.text.x = element_text(angle = 90, colour = "black"), +legend.position = "none", +plot.margin = margin(t = 0, r = 0, b = 0, l = 0, unit = "pt"))+ +annotate("text",x = Inf, y = -Inf, label = letter,hjust = -1,vjust = 1.25) +d +} +IBP("d") +IBPfull<-function(letter){ +IBP(letter)+ +geom_col(data = summpl_[summpl_$plungedistinct=="Underwater pursuit",], +aes(x = 28.5, fill = IBP_detail),col = "black", position = "fill",width = 2.25)+ +geom_col(data = summpl_[summpl_$plungedistinct=="Terrestrial",], +aes(x = 36, fill = IBP_detail),col = "black", position = "fill",width = 2.25)+ +geom_col(data = summpl_[summpl_$plungedistinct=="Plunging",], +aes(x = 31, fill = IBP_detail),col = "black", position = "fill",width = 2.25)+ +geom_col(data = summpl_[summpl_$plungedistinct=="Surface",], +aes(x = 33.5, fill = IBP_detail),col = "black", position = "fill",width = 2.25)+ +annotate("text",x = Inf, y = Inf, label = "*", hjust = 2, vjust = 1.25) +} +IBPfull("l") +### +summ<-avgdf %>% group_by(Order,IAC_detail) %>% count(na.omit = T) +summ$IAC_detail<-ifelse(summ$IAC_detail=="Pneumaticity present"| +summ$IAC_detail=="Pneumaticity absent"| +summ$IAC_detail=="Y",summ$IAC_detail,NA) +summ$label<-summ$Order +summ$number<-summ$n +summ<-as.data.frame(summ) +summa<-summ[which(!is.na(summ$IAC_detail)),] +summpl2<-avgdf %>% group_by(IAC_detail,plungedistinct) %>% count(na.omit = T) +summpl2$IAC_detail<-ifelse(summpl2$IAC_detail=="Pneumaticity present"| +summpl2$IAC_detail=="Pneumaticity absent"| +summpl2$IAC_detail=="Y",summpl2$IAC_detail,NA) +summpl2$number<-summpl2$n +summpl2<-as.data.frame(summpl2) +names(summpl2) +summpl2_<-summpl2[which(!is.na(summpl2$IAC_detail)),] +#IAC +IAC<-function(letter){ +d<-ggtreeplot(gg_tr, summa, aes(y = number), flip=TRUE) + +geom_bar(aes(fill = as.factor(IAC_detail)), position = "fill", +color = "black",stat = "identity")+ +scale_fill_manual(values = c("black","grey","white"))+ +#no_legend()+ +xlim(0.5,38)+ +coord_flip() + no_y_axis()+ +theme(axis.text.x = element_text(angle = 90))+ +ylab("")+ +theme_test() + +theme(axis.line.y = element_blank(), +axis.title.y = element_blank(), +axis.text.y = element_blank(), +axis.ticks.y = element_blank(), +axis.text.x = element_text(angle = 90, colour = "black"), +legend.position = "none", +plot.margin = margin(t = 0, r = 0, b = 0, l = 0, unit = "pt")) + +annotate("text",x = Inf, y = -Inf, label = letter,hjust = -1,vjust = 1.25, size = 5) +# geom_text(aes(x=Inf,y=-Inf,vjust = 1, +# hjust = -1,label=letter)) +d +} +IAC("d") +IACfull<-function(letter){ +IAC(letter)+ +geom_col(data = summpl2_[summpl2_$plungedistinct=="Underwater pursuit",], +aes(x = 28.5, fill = IAC_detail),col = "black", position = "fill",width = 2.25)+ +geom_col(data = summpl2_[summpl2_$plungedistinct=="Terrestrial",], +aes(x = 36, fill = IAC_detail),col = "black", position = "fill",width = 2.25)+ +geom_col(data = summpl2_[summpl2_$plungedistinct=="Plunging",], +aes(x = 31, fill = IAC_detail),col = "black", position = "fill",width = 2.25)+ +geom_col(data = summpl2_[summpl2_$plungedistinct=="Surface",], +aes(x = 33.5, fill = IAC_detail),col = "black", position = "fill",width = 2.25)+ +annotate("text",x = Inf, y = Inf, label = "*", hjust = 2, vjust = 1.25, size = 5) +} +IACfull("m") +###################Plot all together####################### +(gg_tr|addbxplt(1,1,"i")+addbxplt(2,2,"ii")| +addbxplt(3,3,"iii")+addbxplt(4,4,"iv")|# +addbxplt(5,5,"v")+addbxplt(6,6,"vi")) +#umbo height and TM angle +(gg_tr|addbxplt(8,8,"vii")+addbxplt(9,9,"viii", box = "no")|#ESlength & RW +addbxplt(7,7,"ix")+addbxplt(11,11,"x")|#CA and collenght +addbxplt(12,12,"xi", box = "no")+addbxplt(10,10,"xii")|#colvol and air +IACfull("xiii")+IBPfull("xiv")) +(gg_tr|addbxplt(1,1,"i")+addbxplt(2,2,"ii")| +addbxplt(3,3,"iii")+addbxplt(4,4,"iv")|# +addbxplt(5,5,"v")+addbxplt(6,6,"vi"))|addbxplt(8,8,"vii")+addbxplt(9,9,"viii", box = "no")|#ESlength & RW +addbxplt(7,7,"ix")+addbxplt(11,11,"x")|#CA and collenght +addbxplt(12,12,"xi", box = "no")+addbxplt(10,10,"xii")|#colvol and air +IACfull("xiii")+IBPfull("xiv")) +(gg_tr|addbxplt(1,1,"i")+addbxplt(2,2,"ii")| +addbxplt(3,3,"iii")+addbxplt(4,4,"iv")|# +addbxplt(5,5,"v")+addbxplt(6,6,"vi")| +addbxplt(8,8,"vii")+addbxplt(9,9,"viii", box = "no")|#ESlength & RW +addbxplt(7,7,"ix")+addbxplt(11,11,"x")|#CA and collenght +addbxplt(12,12,"xi", box = "no")+addbxplt(10,10,"xii")|#colvol and air +IACfull("xiii")+IBPfull("xiv")) +(gg_tr|addbxplt(1,1,"i")+addbxplt(2,2,"ii")| +addbxplt(3,3,"iii")+addbxplt(4,4,"iv")|# +addbxplt(5,5,"v")+addbxplt(6,6,"vi")) +gg_plungedistinct<-function(index2, letter, box = "yes"){ +ggtreeplot(gg_tr, subset(longdfplotting, +longdfplotting$earmeasuresresid==yvarnames[index2]), aes(y=earmeasureval), flip=TRUE) +{ +if(box == "yes") annotate("text",x = Inf, y = Inf, label = "*", hjust = 2, vjust = 1.25, size = 7) +else annotate("text",x = Inf, y = Inf, label = "", hjust = 2, vjust = 1.25) +} + +#geom_label(aes(x=Inf,y=-Inf,vjust = 1, +# hjust = -1,label=letter, lineheight = 0))+ +geom_vline(xintercept = 1:26,col = "black")+ +#geom_vline(xintercept = -4:30, col = "black")+ +#geom_rect(aes(xmin = -3.5, xmax = 26.5, ymin = -Inf, ymax = -Inf), col = "black", fill = "white", alpha = 0.1)+ +#geom_rect(aes(xmin = -3.5, xmax = 26.5, ymin = Inf, ymax = Inf), col = "black", fill = "white", alpha = 0.1)+ +#geom_line(aes(xmin = -3.5, xmax = 26.5, ymin = 0, ymax = 0), col = "black", size = 1)+ +geom_segment(aes(x = 0.5,xend = 38, y = 0, yend = 0), col = "black")+ +#geom_segment(aes(x = 28,xend = 36, y = 0, yend = 0), col = "black")+ +geom_point(aes(fill = plungedistinct), size = 3,shape = 21, col = "black")+ +scale_fill_manual(values = cbbPalette)+ +#geom_vline(xintercept = 27,col = "black")+ +coord_flip() + no_y_axis()+ +ylab("")+ +xlim(0.5,38)+ +theme_test() + +theme(axis.line.y = element_blank(), +axis.title.y = element_blank(), +axis.text.y = element_blank(), +axis.ticks.y = element_blank(), +#axis.text.x.left = element_text(), +axis.text.x = element_text(angle = 90, colour = "black"), +legend.position = "none", +plot.margin = margin(t = 5, r = 5, b = 0, l = 0, unit = "pt"))+ +geom_boxplot(data = subset(longdfplotting, +longdfplotting$earmeasuresresid==yvarnames[index2]& +longdfplotting$plungedistinct=="Terrestrial"), +aes(x = 36, y = earmeasureval),fill= "white", col = "black", outlier.size = 3, +outlier.colour = "black", width = 2.25, outlier.fill = "white", +outlier.shape = 21)+ +annotate("text",x = Inf, y = -Inf, label = letter,hjust = -1,vjust = 1.25, size = 7) +} +(gg_tr|addbxplt(1,1,"i")+addbxplt(2,2,"ii")| +addbxplt(3,3,"iii")+addbxplt(4,4,"iv")|# +addbxplt(5,5,"v")+addbxplt(6,6,"vi")) +###############scatterplot function########### +gg_plungedistinct<-function(index2, letter, box = "yes"){ +ggtreeplot(gg_tr, subset(longdfplotting, +longdfplotting$earmeasuresresid==yvarnames[index2]), aes(y=earmeasureval), flip=TRUE) +{ +if(box == "yes") annotate("text",x = Inf, y = Inf, label = "*", hjust = 2, vjust = 1.25, size = 8) +else annotate("text",x = Inf, y = Inf, label = "", hjust = 2, vjust = 1.25) +} + +#geom_label(aes(x=Inf,y=-Inf,vjust = 1, +# hjust = -1,label=letter, lineheight = 0))+ +geom_vline(xintercept = 1:26,col = "black")+ +#geom_vline(xintercept = -4:30, col = "black")+ +#geom_rect(aes(xmin = -3.5, xmax = 26.5, ymin = -Inf, ymax = -Inf), col = "black", fill = "white", alpha = 0.1)+ +#geom_rect(aes(xmin = -3.5, xmax = 26.5, ymin = Inf, ymax = Inf), col = "black", fill = "white", alpha = 0.1)+ +#geom_line(aes(xmin = -3.5, xmax = 26.5, ymin = 0, ymax = 0), col = "black", size = 1)+ +geom_segment(aes(x = 0.5,xend = 38, y = 0, yend = 0), col = "black")+ +#geom_segment(aes(x = 28,xend = 36, y = 0, yend = 0), col = "black")+ +geom_point(aes(fill = plungedistinct), size = 3,shape = 21, col = "black")+ +scale_fill_manual(values = cbbPalette)+ +#geom_vline(xintercept = 27,col = "black")+ +coord_flip() + no_y_axis()+ +ylab("")+ +xlim(0.5,38)+ +theme_test() + +theme(axis.line.y = element_blank(), +axis.title.y = element_blank(), +axis.text.y = element_blank(), +axis.ticks.y = element_blank(), +#axis.text.x.left = element_text(), +axis.text.x = element_text(angle = 90, colour = "black"), +legend.position = "none", +plot.margin = margin(t = 5, r = 5, b = 0, l = 0, unit = "pt"))+ +geom_boxplot(data = subset(longdfplotting, +longdfplotting$earmeasuresresid==yvarnames[index2]& +longdfplotting$plungedistinct=="Terrestrial"), +aes(x = 36, y = earmeasureval),fill= "white", col = "black", outlier.size = 3, +outlier.colour = "black", width = 2.25, outlier.fill = "white", +outlier.shape = 21)+ +annotate("text",x = Inf, y = -Inf, label = letter,hjust = -1,vjust = 1.25, size = 8) +} +###################Plot all together####################### +(gg_tr|addbxplt(1,1,"i")+addbxplt(2,2,"ii")| +addbxplt(3,3,"iii")+addbxplt(4,4,"iv")|# +addbxplt(5,5,"v")+addbxplt(6,6,"vi")) +gg_tr <- ggtree(orderPhy, branch.length = "none") + +geom_tiplab(align=TRUE) + +#scale_x_continuous(expand=expand_scale(0.2)) + # make more room for the labels +scale_y_tree()+ +xlim(0,40)+ +ylim(0.5,38)+ +annotate("text", x = 13,y = 36,label = "Terrestrial")+ +annotate("text", x = 13,y = 33.5,label = "Surface-foraging")+ +annotate("text", x = 13,y = 31,label = "Plunge-diving")+ +annotate("text", x = 13,y = 28.5,label = "Underwater-pursuit")+ +annotate("text", x = 1,y = 38,label = "A", size = 8)+ +annotate("text", x = 1,y = 26,label = "B", siz = 8) +gg_tr +gg_tr <- ggtree(orderPhy, branch.length = "none") + +geom_tiplab(align=TRUE) + +#scale_x_continuous(expand=expand_scale(0.2)) + # make more room for the labels +scale_y_tree()+ +xlim(0,40)+ +ylim(0.5,38)+ +annotate("text", x = 13,y = 36,label = "Terrestrial")+ +annotate("text", x = 13,y = 33.5,label = "Surface-foraging")+ +annotate("text", x = 13,y = 31,label = "Plunge-diving")+ +annotate("text", x = 13,y = 28.5,label = "Underwater-pursuit")+ +annotate("text", x = 1,y = 38,label = "A", size = 8)+ +annotate("text", x = 1,y = 26,label = "B", size = 8) +gg_tr +(gg_tr|addbxplt(8,8,"vii")+addbxplt(9,9,"viii", box = "no")|#ESlength & RW +addbxplt(7,7,"ix")+addbxplt(11,11,"x")|#CA and collenght +addbxplt(12,12,"xi", box = "no")+addbxplt(10,10,"xii")|#colvol and air +IACfull("xiii")+IBPfull("xiv")) +IBP<-function(letter){ +d<-ggtreeplot(gg_tr, summb, aes(y = number), flip=TRUE) + +geom_bar(aes(fill = as.factor(IBP_detail)), position = "fill", +color = "black",stat = "identity")+ +scale_fill_manual(values = c("black","grey","white"))+ +#no_legend()+ +xlim(0.5,38)+ +coord_flip() + no_y_axis()+ +theme(axis.text.x = element_text(angle = 90))+ +ylab("")+ +theme_test() + +theme(axis.line.y = element_blank(), +axis.title.y = element_blank(), +axis.text.y = element_blank(), +axis.ticks.y = element_blank(), +axis.text.x = element_text(angle = 90, colour = "black"), +legend.position = "none", +plot.margin = margin(t = 0, r = 0, b = 0, l = 0, unit = "pt"))+ +annotate("text",x = Inf, y = -Inf, label = letter,hjust = -1,vjust = 1.25, size = 8) +d +} +IBP("d") +IBPfull<-function(letter){ +IBP(letter)+ +geom_col(data = summpl_[summpl_$plungedistinct=="Underwater pursuit",], +aes(x = 28.5, fill = IBP_detail),col = "black", position = "fill",width = 2.25)+ +geom_col(data = summpl_[summpl_$plungedistinct=="Terrestrial",], +aes(x = 36, fill = IBP_detail),col = "black", position = "fill",width = 2.25)+ +geom_col(data = summpl_[summpl_$plungedistinct=="Plunging",], +aes(x = 31, fill = IBP_detail),col = "black", position = "fill",width = 2.25)+ +geom_col(data = summpl_[summpl_$plungedistinct=="Surface",], +aes(x = 33.5, fill = IBP_detail),col = "black", position = "fill",width = 2.25)+ +annotate("text",x = Inf, y = Inf, label = "*", hjust = 2, vjust = 1.25, size = 8) +} +IBPfull("l") +### +summ<-avgdf %>% group_by(Order,IAC_detail) %>% count(na.omit = T) +summ$IAC_detail<-ifelse(summ$IAC_detail=="Pneumaticity present"| +summ$IAC_detail=="Pneumaticity absent"| +summ$IAC_detail=="Y",summ$IAC_detail,NA) +summ$label<-summ$Order +summ$number<-summ$n +summ<-as.data.frame(summ) +summa<-summ[which(!is.na(summ$IAC_detail)),] +summpl2<-avgdf %>% group_by(IAC_detail,plungedistinct) %>% count(na.omit = T) +summpl2$IAC_detail<-ifelse(summpl2$IAC_detail=="Pneumaticity present"| +summpl2$IAC_detail=="Pneumaticity absent"| +summpl2$IAC_detail=="Y",summpl2$IAC_detail,NA) +summpl2$number<-summpl2$n +summpl2<-as.data.frame(summpl2) +names(summpl2) +summpl2_<-summpl2[which(!is.na(summpl2$IAC_detail)),] +#IAC +IAC<-function(letter){ +d<-ggtreeplot(gg_tr, summa, aes(y = number), flip=TRUE) + +geom_bar(aes(fill = as.factor(IAC_detail)), position = "fill", +color = "black",stat = "identity")+ +scale_fill_manual(values = c("black","grey","white"))+ +#no_legend()+ +xlim(0.5,38)+ +coord_flip() + no_y_axis()+ +theme(axis.text.x = element_text(angle = 90))+ +ylab("")+ +theme_test() + +theme(axis.line.y = element_blank(), +axis.title.y = element_blank(), +axis.text.y = element_blank(), +axis.ticks.y = element_blank(), +axis.text.x = element_text(angle = 90, colour = "black"), +legend.position = "none", +plot.margin = margin(t = 0, r = 0, b = 0, l = 0, unit = "pt")) + +annotate("text",x = Inf, y = -Inf, label = letter,hjust = -1,vjust = 1.25, size = 8) +# geom_text(aes(x=Inf,y=-Inf,vjust = 1, +# hjust = -1,label=letter)) +d +} +IAC("d") +IACfull<-function(letter){ +IAC(letter)+ +geom_col(data = summpl2_[summpl2_$plungedistinct=="Underwater pursuit",], +aes(x = 28.5, fill = IAC_detail),col = "black", position = "fill",width = 2.25)+ +geom_col(data = summpl2_[summpl2_$plungedistinct=="Terrestrial",], +aes(x = 36, fill = IAC_detail),col = "black", position = "fill",width = 2.25)+ +geom_col(data = summpl2_[summpl2_$plungedistinct=="Plunging",], +aes(x = 31, fill = IAC_detail),col = "black", position = "fill",width = 2.25)+ +geom_col(data = summpl2_[summpl2_$plungedistinct=="Surface",], +aes(x = 33.5, fill = IAC_detail),col = "black", position = "fill",width = 2.25)+ +annotate("text",x = Inf, y = Inf, label = "*", hjust = 2, vjust = 1.25, size = 8) +} +IACfull("m") +(gg_tr|addbxplt(1,1,"i")+addbxplt(2,2,"ii")| +addbxplt(3,3,"iii")+addbxplt(4,4,"iv")|# +addbxplt(5,5,"v")+addbxplt(6,6,"vi")) +#umbo height and TM angle +(gg_tr|addbxplt(8,8,"vii")+addbxplt(9,9,"viii", box = "no")|#ESlength & RW +addbxplt(7,7,"ix")+addbxplt(11,11,"x")|#CA and collenght +addbxplt(12,12,"xi", box = "no")+addbxplt(10,10,"xii")|#colvol and air +IACfull("xiii")+IBPfull("xiv")) diff --git a/Eardata.csv b/Eardata.csv index bedc659..350e91b 100644 --- a/Eardata.csv +++ b/Eardata.csv @@ -4,11 +4,11 @@ Spheniscus demersus,Spheniscus_demersus,Sphenisciformes,Spheniscidae,African pen Larus hartlaubii,Chroicocephalus_hartlaubii,Charadriiformes,Laridae,Hartlaub's gull,H414,Surface foraging,Scanned,Other,Y,Pneumaticity present,22.17,21.49,0.6387115,,1.6285463,399.42,3.7292626,17.7525684,12.8811013,0.4708316,0.4603956,1.4555714,1.0448887,1.8047,0.142,27.35819197 Puffinus griseus,Ardenna_grisea,Procellariiformes,Procellariidae,Sooty shearwater,SW01,Pursuit diving,Scanned,Other,Pneumaticity present,Pneumaticity present,30.52,NA,0.5687735,,1.7550923,231.33,4.14108,14.8505159,14.1101799,0.8797251,3.0077953,2.6428105,1.1576382,2.9779,0.37039,16.0393058 Larus dominicanus,Larus_dominicanus,Charadriiformes,Laridae,Kelp gull,K151,Surface foraging,Scanned,Other,Y,Y,40.95,62.3,1.017922,,2.537805,3236.84,5.237897,16.261305,36.053742,0.97365,1.818927,2.394297,2.027716,3.8787,0.430434,37.02946849 -Morus capensis,Morus_capensis,Suliformes,Sulidae,Gannet,G045,Pursuit diving,Scanned,Poor LF,Y,Y,47.58,275,0.592118,,1.5276351,7067.93,6.6173265,12.0753945,27.8116976,1.1589345,3.511894,2.2928683,1.0647901,8.6,1.029,23.99764404 -Phalacrocorax capensis,Phalacrocorax_capensis,Suliformes,Phalacrocoridae,Cape Cormorant,CC209,Pursuit diving,Scanned,Poor LF,Y,Pneumaticity absent,27,71.26,0.3453295,,0.79324334,372.35,5.08996474,13.0261082,9.22449752,0.44051429,2.72894333,2.03706372,0.45345296,3.8696,0.266328,20.94029122 +Morus capensis,Morus_capensis,Suliformes,Sulidae,Cape gannet,G045,Pursuit diving,Scanned,Poor LF,Y,Y,47.58,275,0.592118,,1.5276351,7067.93,6.6173265,12.0753945,27.8116976,1.1589345,3.511894,2.2928683,1.0647901,8.6,1.029,23.99764404 +Phalacrocorax capensis,Phalacrocorax_capensis,Suliformes,Phalacrocoridae,Cape cormorant,CC209,Pursuit diving,Scanned,Poor LF,Y,Pneumaticity absent,27,71.26,0.3453295,,0.79324334,372.35,5.08996474,13.0261082,9.22449752,0.44051429,2.72894333,2.03706372,0.45345296,3.8696,0.266328,20.94029122 Phoenicopterus roseus,Phoenicopterus_roseus,Phoenicopteriformes,Phoenicopteridae,Greater flamingo,Flamingo01,Surface foraging,Scanned,Other,Y,Pneumaticity present,32.43,NA,0.897117,,2.1548053,1379.64,5.7269092,18.206483,23.9107099,1.114212,4.407708,3.3531699,1.706508,3.31,0.448037,21.45974904 Procellaria aequinoctialis,Procellaria_aequinoctialis,Procellariiformes,Procellariidae,White-chinned petrel,WCP03,Pursuit diving,Scanned,Other,Pneumaticity present,Pneumaticity present,43.39,NA,0.6965724,fluid filled,2.3398132,NA,6.2084629,15.854649,19.97404,1.0531436,3.1105181,2.7006765,2.0672644,4.7777,0.612506,18.9661125 -Chionis minor,Chionis_minor,Charadriiformes,Chionidae,Lesser Sheathbill,SB-01-2019,Terrestrial,Scanned,Other,Y,Y,21.72,NA,0.487271,,1.5954347,751.71,4.6720255,13.9758777,12.2568029,0.4497441,2.3852071,1.5378967,1.2606874,1.75,0.104,27.25283756 +Chionis minor,Chionis_minor,Charadriiformes,Chionidae,Lesser sheathbill,SB-01-2019,Terrestrial,Scanned,Other,Y,Y,21.72,NA,0.487271,,1.5954347,751.71,4.6720255,13.9758777,12.2568029,0.4497441,2.3852071,1.5378967,1.2606874,1.75,0.104,27.25283756 Macronectes halli,Macronectes_halli,Procellariiformes,Procellariidae,Northern giant petrel,NGP-01-2019,Surface foraging,Scanned,Other,Y,Y,53.82,271.5,0.5378209,,1.8362029,5937.11,6.5958948,7.9291175,43.0391185,1.3891691,6.155614,3.6991239,1.7127285,5.6,0.851,30.98191466 Bucorvus abyssinicus,Bucorvus_leadbeateri,Bucerotiformes,Bucorvidae,Southern ground hornbill,GHB01,Terrestrial,Scanned,Other,,,69.06,NA,0.8311657,fluid filled,3.9816637,NA,8.3393286,8.9851082,88.3744713,1.9769213,0.3481421,10.2280263,3.5247887,6.267897,0.897199875,44.70308014 Aethopyga siparaja,Cinnyris_chalybeus,Passeriformes, Nectariniidae,Southern double-collared sunbird,DCSB01,Terrestrial,Scanned,Poor LF,Y,Y,11,NA,0.31907899,,0.61324873,47.16,1.99507714,13.58151162,5.35102153,0.21222748,0.03260038,0.3605546,0.61367124,0.895437,0.018883125,25.21361291 diff --git a/Plot PCA.R b/Plot PCA.R index 30aaf9f..ceefe11 100644 --- a/Plot PCA.R +++ b/Plot PCA.R @@ -19,7 +19,7 @@ p<-ggplot(d, aes(x = reorder(PC1,-percentexplained), y = percentexplained))+ ylab("Percent variance \n explained") p -#remove lavels for inset plot +#remove labels for inset plot p<-ggplot(d[1:6,], aes(x = reorder(PC1,-percentexplained), y = percentexplained))+ geom_bar(stat = "identity")+ theme_classic()+ @@ -32,19 +32,6 @@ p<-ggplot(d[1:6,], aes(x = reorder(PC1,-percentexplained), y = percentexplained) p -themejz<-function (base_size = 11, base_family = "", base_line_size = base_size/22, - base_rect_size = base_size/22) -{ - theme_grey(base_size = base_size, base_family = base_family, - base_line_size = base_line_size, base_rect_size = base_rect_size) %+replace% - theme(panel.background = element_blank(), panel.border = element_rect(), panel.grid = element_line(), - panel.grid.minor = element_blank(), - strip.background = element_rect(fill = "grey85", - colour = "grey20"), legend.key = element_rect(fill = "white", - colour = NA), complete = TRUE) -} - - ################Make a grouping of orders that includes species with one underwater-pursuit species##################### speciesPCAvalues$Order<-as.character(speciesPCAvalues$Order) @@ -285,7 +272,7 @@ loadings2<-loadings1 + annotation_custom(ggplotGrob(p), ymin = 0, ymax = 1) loadings2 -ggarrange(loadings2,plunge,divescore, order, +ggarrange(loadings1,plunge,divescore, order, labels = c("A","B","C","D")) ggsave("D:/00_Manuscripts/0Avian aquatic hearing project/___Oct 1 version/PCAOct 4_noair.pdf",width = 10, height = 10) diff --git a/Residualphylogplots_a panel top.R b/Residualphylogplots_a panel top.R index 8ec6508..da2379d 100644 --- a/Residualphylogplots_a panel top.R +++ b/Residualphylogplots_a panel top.R @@ -1,5 +1,4 @@ -#Plotting adapted from: -#https://thackl.github.io/ggtree-composite-plots +#Plotting adapted from: https://thackl.github.io/ggtree-composite-plots library(patchwork) library(viridis) @@ -85,8 +84,8 @@ annotate("text", x = 13,y = 36,label = "Terrestrial")+ annotate("text", x = 13,y = 33.5,label = "Surface-foraging")+ annotate("text", x = 13,y = 31,label = "Plunge-diving")+ annotate("text", x = 13,y = 28.5,label = "Underwater-pursuit")+ - annotate("text", x = 1,y = 38,label = "A")+ - annotate("text", x = 1,y = 26,label = "B") + annotate("text", x = 1,y = 38,label = "A", size = 8)+ + annotate("text", x = 1,y = 26,label = "B", size = 8) gg_tr #reversed phylogenetic tree @@ -108,7 +107,7 @@ gg_plungedistinct<-function(index2, letter, box = "yes"){ ggtreeplot(gg_tr, subset(longdfplotting, longdfplotting$earmeasuresresid==yvarnames[index2]), aes(y=earmeasureval), flip=TRUE) +{ - if(box == "yes") annotate("text",x = Inf, y = Inf, label = "*", hjust = 2, vjust = 1.25, size = 5) + if(box == "yes") annotate("text",x = Inf, y = Inf, label = "*", hjust = 2, vjust = 1.25, size = 8) else annotate("text",x = Inf, y = Inf, label = "", hjust = 2, vjust = 1.25) } + #geom_label(aes(x=Inf,y=-Inf,vjust = 1, @@ -142,7 +141,7 @@ gg_plungedistinct<-function(index2, letter, box = "yes"){ aes(x = 36, y = earmeasureval),fill= "white", col = "black", outlier.size = 3, outlier.colour = "black", width = 2.25, outlier.fill = "white", outlier.shape = 21)+ - annotate("text",x = Inf, y = -Inf, label = letter,hjust = -1,vjust = 1.25, size = 5) + annotate("text",x = Inf, y = -Inf, label = letter,hjust = -1,vjust = 1.25, size = 8) } @@ -231,7 +230,7 @@ IBP<-function(letter){ axis.text.x = element_text(angle = 90, colour = "black"), legend.position = "none", plot.margin = margin(t = 0, r = 0, b = 0, l = 0, unit = "pt"))+ - annotate("text",x = Inf, y = -Inf, label = letter,hjust = -1,vjust = 1.25) + annotate("text",x = Inf, y = -Inf, label = letter,hjust = -1,vjust = 1.25, size = 8) d @@ -249,7 +248,7 @@ IBPfull<-function(letter){ aes(x = 31, fill = IBP_detail),col = "black", position = "fill",width = 2.25)+ geom_col(data = summpl_[summpl_$plungedistinct=="Surface",], aes(x = 33.5, fill = IBP_detail),col = "black", position = "fill",width = 2.25)+ - annotate("text",x = Inf, y = Inf, label = "*", hjust = 2, vjust = 1.25) + annotate("text",x = Inf, y = Inf, label = "*", hjust = 2, vjust = 1.25, size = 8) } IBPfull("l") @@ -296,7 +295,7 @@ IAC<-function(letter){ axis.text.x = element_text(angle = 90, colour = "black"), legend.position = "none", plot.margin = margin(t = 0, r = 0, b = 0, l = 0, unit = "pt")) + - annotate("text",x = Inf, y = -Inf, label = letter,hjust = -1,vjust = 1.25, size = 5) + annotate("text",x = Inf, y = -Inf, label = letter,hjust = -1,vjust = 1.25, size = 8) # geom_text(aes(x=Inf,y=-Inf,vjust = 1, # hjust = -1,label=letter)) @@ -316,7 +315,7 @@ IACfull<-function(letter){ aes(x = 31, fill = IAC_detail),col = "black", position = "fill",width = 2.25)+ geom_col(data = summpl2_[summpl2_$plungedistinct=="Surface",], aes(x = 33.5, fill = IAC_detail),col = "black", position = "fill",width = 2.25)+ - annotate("text",x = Inf, y = Inf, label = "*", hjust = 2, vjust = 1.25, size = 5) + annotate("text",x = Inf, y = Inf, label = "*", hjust = 2, vjust = 1.25, size = 8) } IACfull("m") @@ -332,3 +331,11 @@ IACfull("m") addbxplt(7,7,"ix")+addbxplt(11,11,"x")|#CA and collenght addbxplt(12,12,"xi", box = "no")+addbxplt(10,10,"xii")|#colvol and air IACfull("xiii")+IBPfull("xiv")) + +(gg_tr|addbxplt(1,1,"i")+addbxplt(2,2,"ii")| + addbxplt(3,3,"iii")+addbxplt(4,4,"iv")|# + addbxplt(5,5,"v")+addbxplt(6,6,"vi")| + addbxplt(8,8,"vii")+addbxplt(9,9,"viii", box = "no")|#ESlength & RW + addbxplt(7,7,"ix")+addbxplt(11,11,"x")|#CA and collenght + addbxplt(12,12,"xi", box = "no")+addbxplt(10,10,"xii")|#colvol and air + IACfull("xiii")+IBPfull("xiv")) diff --git a/Run PGLS and AIC.R b/Run PGLS and AIC.R index f1b8f9d..e50361c 100644 --- a/Run PGLS and AIC.R +++ b/Run PGLS and AIC.R @@ -84,8 +84,8 @@ body_add_flextable(toprint,flexall)#add pgls output table body_end_section_landscape(toprint) #print to file -print(toprint,target = "D:/Analysis_plots/AIC best model Dec 9 no terr.docx") -print(toprint,target = "D:/Analysis_plots/AIC Dec 1 compare_terr.docx") +print(toprint,target = "E:/Analysis_plots/AIC best model Mar31 no terr.docx") +print(toprint,target = "E:/Analysis_plots/AIC Mar 31 compare_terr.docx") ########(2)Get model details for best model########### @@ -122,6 +122,6 @@ toprint<-read_docx() #create word doc object body_add_flextable(toprint,flexall)#add pgls output table body_end_section_landscape(toprint) -print(toprint,target = "D:/Analysis_plots/AIC Details Dec 9 no terr.docx") -print(toprint,target = "D:/Analysis_plots/DetailsNov 12 terr compare.docx") +print(toprint,target = "E:/Analysis_plots/AIC Details Dec 31 no terr.docx") +print(toprint,target = "E:/Analysis_plots/DetailsMar 31 terr compare.docx")