rm(list=ls())
library(ggplot2)

setwd("~/Dropbox/FCU/Teaching/Mentoring/2022Spring-Current_Professor/2022Fall/MinhsuanLin/0FractionalBrownianMotionTraitEvolution/rcode_dcj/AncCIsim")

modelset<-c("BM")#,"OU","EB","LBD","FBM","FOU")

taxa_sizes <- c(4, 8, 16, 32)
tree_types <- c("balanced", "coal", "birthdeath", "purebirth")
#AncCIsimBM.RDataa
for(model in modelset){
  filetoload<-paste("AncCIsim",model,".RData",sep="")
  # tree_results
  results_treetype<-results$`4_balanced`[[2]]$results_df
  print(filetoload)
 # load(filetoload)
}
CreatePlot<-function(model=model){
  ggplot(results_treetype
         , aes(x=Node, y=Mean)) +
    geom_point() +
    geom_errorbar(aes(ymin=LowerCI, ymax=UpperCI), width=0.2) +
    theme_minimal() +
    labs(x="Node", y="Mean", title=paste(model, ": Mean and 95% CI",sep=""))
}


load("AncCIsimBM.RData")
results_treetype<-results$`4_balanced`[[2]]$results_df
p.bm<-CreatePlot(model="BM")

load("AncCIsimOU.RData")
results_treetype<-results$`4_balanced`[[2]]$results_df
p.ou<-CreatePlot(model="OU")

load("AncCIsimEB.RData")
results_treetype<-results$`4_balanced`[[2]]$results_df
p.eb<-CreatePlot(model="EB")

load("AncCIsimLBD.RData")
results_treetype<-results$`4_balanced`[[2]]$results_df
p.lbd<-CreatePlot(model="LBD")

load("AncCIsimFBM.RData")
results_treetype<-results$`4_balanced`[[1]]$results_df
p.fbm<-CreatePlot(model="FBM")

load("AncCIsimFOU.RData")
results_treetype<-results$`4_balanced`[[2]]$results_df
p.fou<-CreatePlot(model="FOU")

gridExtra::grid.arrange(p.bm,p.ou,p.eb,p.lbd,p.fbm,p.fou,nrow=2)