This vignette gives further detail on how to use the functions in biogrowth to prepare publication ready figures. For details on how to use the base functions of the package, please check the vignettes for model fitting and growth predictions.
The functions in biogrowth use
cowplot::theme_cowplot as default, that has a nice clean
theme and could be used in a publication as is. However, more control
over formatting options can be needed in order to standardize plots or
when preparing figures for a specific journal.
Moreover, every plot is based on ggplot2, and
therefore the plots can be manipulated in the same way. In order to ease
manipulation, plotting methods in biogrowth include
arguments to control the aesthetics that would often would within the
“geom_” definition (such as
As an illustration for this, we will use a growth model fitted to data under dynamic environmental conditions.
data("example_dynamic_growth") data("example_env_conditions") sec_models <- list(temperature = "CPM", aw = "CPM") known_pars <- list(Nmax = 1e4, # Primary model N0 = 1e0, Q0 = 1e-3, # Initial values of the primary model mu_opt = 4, # mu_opt of the gamma model temperature_n = 1, # Secondary model for temperature aw_xmax = 1, aw_xmin = .9, aw_n = 1 # Secondary model for water activity ) my_start <- list(temperature_xmin = 25, temperature_xopt = 35, temperature_xmax = 40, aw_xopt = .95) my_model <- fit_growth(example_dynamic_growth, sec_models, my_start, known_pars, environment = "dynamic", env_conditions = example_env_conditions )
By default, the S3
plot() methods use the
As mentioned, the plot methods include a large list of additional
arguments that can be used to edit the aesthetics of the plot. A whole
list of arguments is available from the class documentation
(e.g. accessible by typing
?GrowthFit in the console). In
the case of
plot.GrowthFit(), the plot method includes the
This provides plenty of options to edit the aesthetics of the plot. For instance:
Note that the plot function returns an instance of
ggplot. This allows further editing of the plot using
layers with the functions included in ggplot2. This
provides plenty of options to edit the plot
In some cases, the automatic scaling that ggplot2 uses might not be optimal. We can use the coord_cartesian() function to change the limits of the x- and y-axis
plot_grid() function from cowplot
provides a convenient way to combine different plots into a grid. For
ggsave() will automatically save the last plot to a
specified location. It needs a filename as a string, for instance
“static_prediction.pdf” to save the figure as a pdf. It also needs a
location to save to (defaults to the working directory), and optionally
the user can set dimentions and units.
GlobalGrowthFit are a subclass of
provides simple access to several attributes of the model. For instance,
the the entry
best_prediction of an instance of
GrowthFit includes an instance of
GrowthPrediction with the fitted model.
my_model$best_prediction #> Growth prediction under dynamic environmental conditions #> #> Environmental factors included: temperature, aw #> #> Parameters of the Baranyi primary model: #> mu_opt Nmax N0 Q0 #> 4e+00 1e+04 1e+00 1e-03 #> #> Parameter mu defined in log-10 scale #> #> Population size defined in log-10 scale #> #> Secondary model for temperature: #> xmin xopt xmax n #> "26.5764432438481" "35.9372454868183" "50.5763327654148" "1" #> model #> "CPM" #> #> Secondary model for aw: #> xmin xopt xmax n #> "0.9" "0.988189183173101" "1" "1" #> model #> "CPM"
In a similar way, the
simulation entry of this instance
includes a tibble with the model simulation
This allows making plots directly using this data using ggplot2 (or similar packages)