Skip to contents

Visualize simulation results of a stock-and-flow model. Plot the evolution of stocks over time, with the option of also showing other model variables.

Usage

# S3 method for class 'sdbuildR_sim'
plot(
  x,
  add_constants = FALSE,
  vars = NULL,
  palette = "Dark 2",
  colors = NULL,
  font_family = "Times New Roman",
  font_size = 16,
  wrap_width = 25,
  showlegend = TRUE,
  ...
)

Arguments

x

Output of simulate().

add_constants

If TRUE, include constants in plot. Defaults to FALSE.

vars

Variables to plot. Defaults to NULL to plot all variables.

palette

Colour palette. Must be one of hcl.pals().

colors

Vector of colours. If NULL, the color palette will be used. If specified, will override palette. The number of colours must be equal to the number of variables in the simulation dataframe. Defaults to NULL.

font_family

Font family. Defaults to "Times New Roman".

font_size

Font size. Defaults to 16.

wrap_width

Width of text wrapping for labels. Must be an integer. Defaults to 25.

showlegend

Whether to show legend. Must be TRUE or FALSE. Defaults to TRUE.

...

Optional parameters

Value

Plot object

Examples

sfm <- xmile("SIR")
sim <- simulate(sfm)
plot(sim)
# The default plot title and axis labels can be changed like so: plot(sim, main = "Simulated trajectory", xlab = "Time", ylab = "Value")
# Add constants to the plot plot(sim, add_constants = TRUE)
# Plot all model variables sim <- simulate(sfm, only_stocks = FALSE) plot(sim, add_constants = TRUE)