Skip to content

Commit

Permalink
Add option to save a plot_model() figure to a file
Browse files Browse the repository at this point in the history
  • Loading branch information
bodkan committed Jul 21, 2023
1 parent 5b677bd commit e600784
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
9 changes: 7 additions & 2 deletions R/visualization.R
Expand Up @@ -264,6 +264,8 @@ sort_splits <- function(model) {
#' vector of population names. If \code{NULL} (the default), the default plotting
#' algorithm will be used, ordering populations from the most ancestral to the
#' most recent using an in-order tree traversal.
#' @param file Output file for a figure saved via \code{ggsave}
#' @param ... Optional argument which will be passed to \code{ggsave}
#'
#' @return A ggplot2 object with the visualized slendr model
#'
Expand All @@ -282,7 +284,7 @@ sort_splits <- function(model) {
#' labs geom_segment arrow
#' @export
plot_model <- function(model, sizes = TRUE, proportions = FALSE, gene_flow = TRUE, log = FALSE,
order = NULL) {
order = NULL, file = NULL, ...) {
populations <- model$populations

log10_ydelta <- 0.001
Expand Down Expand Up @@ -519,7 +521,10 @@ plot_model <- function(model, sizes = TRUE, proportions = FALSE, gene_flow = TRU

p <- p + scale_y_continuous(trans = trans)

p
if (!is.null(file))
ggplot2::ggsave(file, plot = p, ...)
else
p
}

#' Animate the simulated population dynamics
Expand Down
12 changes: 11 additions & 1 deletion docs/reference/plot_model.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/plot_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e600784

Please sign in to comment.