R/ggplot_bootstrap.R

#' Function for creating PBBC plots
#'
#' This function takes the output from \link{running.bootstrap} and creates a plot.
#'
#' @param result_list Output list from \link{running.bootstrap}
#' @return Plot in the form of a ggplot2 object
#' @import ggplot2
#' @export

ggplot_bootstrap <- function(result_list){
  result.df<-result_list$result.df
  raw<-result_list$raw
  df<-data.frame(raw)
  alpha0 <- c(raw[,1], raw[,3]); alpha1 <- c(raw[,2], raw[,4]);
  # Structuring the data to be plotted in a dataframe
  df<-data.frame(alpha0, alpha1, est =
                   c(rep("Original",nrow(raw)),rep("PBBC", nrow(raw))))
  true.param <- data.frame(alpha0 = result.df$true.param[1], alpha1 = result.df$true.param[2])
  # Finding common limits for the separate plots
  xlim<-c(min(raw[,1],result.df$true_param[1], raw[,3]),max(raw[,1],result.df$true_param[1], raw[,3]))
  ylim<-c(min(raw[,2],result.df$true_param[2], raw[,4]),max(raw[,2],result.df$true_param[2], raw[,4]))
  p<-ggplot(df, aes(alpha0, alpha1))+
    labs(y=expression(alpha["1"]), x = expression(alpha["0"]))+xlim(xlim)+ylim(ylim)
  #     p<-p+geom_point(color=ifelse(df$est=="Original", "blue", "red"))
  p<-p+facet_grid(. ~ est) +geom_point(data=true.param, colour= "green", pch=15, size=3)
  return(p)
}
Sondre91/STGARCH documentation built on May 9, 2019, 1:52 p.m.