R/plot_meanTs.R

Defines functions plot_meanTs

Documented in plot_meanTs

#' Plot means of simulated T and estimated T
#'
#' This is a wrapper function for plotting values of simulated T and true T.
#' Means are taken within repeated values of Ni.
#'
#' @param dat Data to be plotted
#' @param legend Legend position; passed to legend.postion()
#'
#' @export
#'

plot_meanTs <- function(dat, legend){
  dat <- na.omit(dat)
  means <- data.frame(Ni = seq(10, 1000, by = 10),
                       Ttrue = tapply(dat[,"Ttrue"], INDEX = factor(dat$i), FUN = mean),
                       That = tapply(dat[,"That"], INDEX = factor(dat$i), FUN = mean))
  cols <- c("Estimated" = "#f04546", "True" = "#3591d1")
  library(ggplot2)
  ggplot(data = means, aes(x = Ni)) +
    geom_line(aes(y = That/1000000, color = names(cols)[1])) +
    geom_line(aes(y = Ttrue/1000000, color = names(cols)[2])) +
    scale_colour_manual(name = "", values = cols) +
    scale_y_continuous(limits = c(1.075, 1.175)) +
    ylab("Mean Population Size (Millions)") + xlab(bquote(paste(nu, " (nu)"))) +
    theme_bw() +
    theme(legend.position = legend)
}
chrisroberts2112/msProject documentation built on April 21, 2022, 1:59 a.m.