R/plot_summary_stats_complex.R

#' Plots summary statistics for distances between sequences
#' @param summary_table The data returned by a simulation
#' @importFrom magrittr "%>%"
#' @export
plot_summary_stats_complex <- function(summary_table, title, max_line_width = 1, timejump = 10^6)
{
  max_num_seq <- max(summary_table$num_seq)

  summary_table$quant25 <- sapply(summary_table$quantiles_dist, function(x) x["25%"])
  summary_table$quant75 <- sapply(summary_table$quantiles_dist, function(x) x["75%"])
  summary_table <- summary_table %>%
    tidyr::gather("stat", "value", c(mean_dist, median_dist, quant25, quant75)) %>%
    dplyr::mutate(relative_size = (num_seq*max_line_width/max_num_seq)) %>%
    dplyr::select(time, relative_size, stat, value)

  #p <- ggplot2::ggplot(data = summary_table,
  #                     ggplot2::aes(x = time))
  #p <- p + ggplot2::geom_line(ggplot2::aes(y = value, color=stat, size=relative_size)) +
  #         ggplot2::scale_size_continuous(range = c(0.01, 2.01))
  #p <- p + ggplot2::labs(x = paste0("time (in ", timejump, " years)"), y = "mean pairwise sequence distance",
  #                       title = title)
  #p <- p + ggplot2::guides(size=ggplot2::guide_legend(title="Number of sequences"))
  #p <- p + ggplot2::guides(color=ggplot2::guide_legend(title="Statistic being compared"))
  p <- ggplot2::ggplot(data = summary_table,
                       ggplot2::aes(x = time))
  p <- p + ggplot2::geom_line(ggplot2::aes(y = value, color=stat))
  p <- p + ggplot2::labs(x = paste0("time (in ", timejump, " years)"), y = "mean pairwise sequence distance",
                         title = title)
  p <- p + ggplot2::guides(color=ggplot2::guide_legend(title="Statistic being compared"))
  return(p)
}
sams25/rcombinator_old documentation built on May 28, 2019, 8:40 a.m.