From 104aa63d442ba663500a018ac1fb6c53dd5461ce Mon Sep 17 00:00:00 2001 From: Martin Petr Date: Wed, 21 Jun 2023 09:22:23 +0200 Subject: [PATCH] Add option not to draw gene-flow arrows --- R/visualization.R | 5 +++-- man/plot_model.Rd | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/R/visualization.R b/R/visualization.R index 984b2bc94..283295355 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -256,6 +256,7 @@ sort_splits <- function(model) { #' @param sizes Should population size changes be visualized? #' @param proportions Should gene flow proportions be visualized (\code{FALSE} #' by default to prevent cluttering and overplotting) +#' @param gene_flow Should gene-flow arrows be visualized (default \code{TRUE}). #' @param log Should the y-axis be plotted on a log scale? Useful for models #' over very long time-scales. #' @@ -275,7 +276,7 @@ sort_splits <- function(model) { #' geom_polygon geom_label scale_y_continuous scale_color_discrete scale_fill_discrete #' labs geom_segment arrow #' @export -plot_model <- function(model, sizes = TRUE, proportions = FALSE, log = FALSE) { +plot_model <- function(model, sizes = TRUE, proportions = FALSE, gene_flow = TRUE, log = FALSE) { populations <- model$populations log10_ydelta <- 0.001 @@ -415,7 +416,7 @@ plot_model <- function(model, sizes = TRUE, proportions = FALSE, log = FALSE) { # generate a table of gene flow events to be used for plotting gene flow # arrows - if (!is.null(model$geneflow)) { + if (!is.null(model$geneflow) && gene_flow) { gene_flow <- model$geneflow %>% dplyr::mutate( x = purrr::map_dbl(from, ~ centers[centers$pop == .x, ]$center), diff --git a/man/plot_model.Rd b/man/plot_model.Rd index 7cb298b7c..a7d96762f 100644 --- a/man/plot_model.Rd +++ b/man/plot_model.Rd @@ -4,7 +4,13 @@ \alias{plot_model} \title{Plot demographic history encoded in a slendr model} \usage{ -plot_model(model, sizes = TRUE, proportions = FALSE, log = FALSE) +plot_model( + model, + sizes = TRUE, + proportions = FALSE, + gene_flow = TRUE, + log = FALSE +) } \arguments{ \item{model}{Compiled \code{slendr_model} model object} @@ -14,6 +20,8 @@ plot_model(model, sizes = TRUE, proportions = FALSE, log = FALSE) \item{proportions}{Should gene flow proportions be visualized (\code{FALSE} by default to prevent cluttering and overplotting)} +\item{gene_flow}{Should gene-flow arrows be visualized (default \code{TRUE}).} + \item{log}{Should the y-axis be plotted on a log scale? Useful for models over very long time-scales.} }