R/plot_nsim.R

#'Plot Simulations
#'
#'Function that calls the full data frame with all simulations and all runsettings. Plot function plots the median, lower and upper uncertainty bounds
#'by each simulation by each runsetting for the selected parameters.
#' @param df The data frame with combined simulations and runsettings with summary statistics (med, upper, lower, bias, coverage indicator)
#' @param plotpars  #selected parameters to plot
#'
#' @return Saves plot of posterior estimates by sim number and runsetting to fig.dir
#' @export
#'
#' @examples
plot_nsim <- function(df) {
  pd <- position_dodge(0.1)

    g <- ggplot(df , mapping = aes(y = median, x = as.factor(sim), color=sim)) +
    geom_point() +
    geom_errorbar(aes(ymin = lower, ymax = upper),
                  width = .1,
                  position = pd) +
    labs(x = "Nsim", y = "Posterior Estimates: 50% (2.5%, 97.5%)") +
    theme(
      text = element_text(size = 20),
      axis.text.x = element_text(angle = 90, hjust = 1),
      plot.title = element_text(hjust = 0.5)
    ) +
      geom_hline(data = df,aes(yintercept = truth),
                 linetype = "dashed",
                 color = "red") +
    facet_grid(parameter ~ runsetting,scales="free_y")

    g1 <- g + theme(legend.position="none")
    print(g1)
}
Enpeterson/outputsim documentation built on May 24, 2019, 9:53 a.m.