bgf_plot: Advanced 'BGF' visualization

View source: R/bgf_plot.R

bgf_plotR Documentation

Advanced BGF visualization

Description

A set of functions that allow advanced data visualization employing ggplot2 and plotly. The two main functions are bgf_plot, which is a high end wrapper to produce frequently needed plots and plot_curve, which is offers more freedom during plot creation.

Usage

bgf_plot(x, type = "all", ...)

plot_curve(
  x,
  what,
  color,
  col = bgfanalyzer::BGF_defaultcolors,
  coltitle = "Reactor:",
  col_names = NULL,
  title = NULL,
  subtitle = NULL,
  xlab = ggplot2::waiver(),
  ylab = ggplot2::waiver(),
  keep_excluded = TRUE,
  interaction = FALSE
)

plot_product_curve(x, ...)

plot_production_curve(x, ...)

plot_rel_production_curve(x, ...)

plot_netProduct_by_Layout(
  x,
  col = bgfanalyzer::BGF_defaultcolors[2 + 3 * c(0:7)],
  coltitle = "Layout:",
  col_names = NULL,
  title = NULL,
  subtitle = NULL,
  xlab = paste0("observation time [", x$ExpParam$timeScale, "s]"),
  ylab = "net exhaust gas volume",
  keep_excluded = TRUE,
  interaction = FALSE
)

colplot_yield(
  x,
  hide = NULL,
  Excluded = FALSE,
  col = bgfanalyzer::BGF_defaultcolors[2 + 3 * c(0:7)],
  coltitle = "Layout:",
  col_names = NULL,
  title = NULL,
  subtitle = NULL,
  yield_label = FALSE,
  yield_label_pos = 100,
  yield_unit = "Nml/gVS",
  interaction = FALSE
)

boxplot_yield(
  x,
  timep = "all",
  hide = NULL,
  Excluded = FALSE,
  col = bgfanalyzer::BGF_defaultcolors[2 + 3 * c(0:7)],
  coltitle = "Layout:",
  col_names = NULL,
  title = NULL,
  subtitle = NULL,
  yield_label = FALSE,
  yield_label_pos = 100,
  yield_unit = "Nml/gVS",
  interaction = FALSE
)

Arguments

x

a BGF

type

a character indicating which plots should be produced. Possible values are 'product', 'netProduct', 'production', 'relProduction','yield_col' or 'yield_box, which yield in a product line plot, a net product line plot, a production line plot, a relative production line plot, a yield col plot or a yield box plot, respectively. It is possible to use any combination of valid types (e.g. 'type = c("product","production","yield_box")'). The default selection is 'all', which will cause the function to produce all plots.

...

further arguments passed to plot_curve, plot_netProduct_by_Layout, colplot_yield or boxplot_yield

what

the name of a (numeric) column in the BioGasData-layer of a BGF. Must be specified without quotes

color

the name another column in the BioGasData-layer holding a grouping variable

col

a vector with colors to be used to differentiate between levels of the grouping variable. In the default setting, 24 colors are provided

coltitle

the title of the plot legend. default ='Reactor:'

col_names

default is NULL. If specified, a character with the same length as levels in the 'color' argument is expected. It can be used change the default labels in the legend

title

default is NULL. If specified, a title for the plot can be created

subtitle

default is NULL. If specified, a subtitle for the plot can be created

xlab

can be used to change the default title of the x-axis. Default is waiver

ylab

can be used to change the default title of the y-axis. Default is waiver

keep_excluded

logic, default is TRUE. Should fermentations that are marked as 'Excluded' in the metaData-layer be shown in the plot?

interaction

logic, default is FALSE. If TRUE the plot will be created using plotly as plot engine instead of ggplot2

hide

default is NULL. Can be a character specifying reactor layouts to hide from the plot

Excluded

logic; default is FALSE. Should fermentations that are marked as 'Excluded' in the metaData-layer appear in the plot?

yield_label

logic; default is FAlSE. Should the mean yield be shown as a label on the plot?

yield_label_pos

a numeric specifying the position of the yield label in the plot

yield_unit

a character specifying the unit of the yield. The default is 'Nml/gVS', which is read 'norm milliliter per gram of volatile solutes'

timep

a numeric specifying the time point at which to calculate the yield for the individual reactor layouts. Alternatively, using the character expressions 'all' will draw the box over all values in the 'yield' and 'max' will draw the box using the final 'yield' value

Details

The main function for advanced data visualization purposes is bgf_plot. It is a wrapper that successively calls plot_product_curve, plot_production_curve, plot_rel_production_curve, plot_netProduct_by_Layout, colplot_yield and boxplot_yield. It stores the output of each function in a list which is returned

The second function, that allows advanced data visualization is plot_curve. It can be used to draw a line plot from data in the BioGasData-layer of a BGF. In this plot, the 'time' column representing the fermentation/ observation time will be on the x-axis. The y-axis can be any other column of the BioGasData-layer and is specified via the 'what' argument. Furthermore, it is required to provide a grouping variable in the 'color' argument. If that grouping variable has more than 24 levels, the 'col' argument must be changed as in the default setting only 24 colors are available for plotting.

There exist several wrapper functions, that internally call plot_curve exist. These are:

  • plot_product_curve: Produces a 'product' line plot. Argument 'what' set to 'product' and argument 'color' set to 'reactor'. Can be called via bgf_plot when 'type = "product"' or 'type = "all"'. In the later case, the plot is stored in a list with the label 'product_curve'.

  • plot_production_curve: Produces a 'production' line plot. Argument 'what' set to 'production' and argument 'color' set to 'reactor'. Can be called via bgf_plot when 'type = "production"' or 'type = "all"'. In the later case, the plot is stored in a list with the label 'production_curve'.

  • plot_rel_production_curve: Produces an inverted 'rel_production' line plot. Argument 'what' set to 'c(100-rel_production)' and argument 'color' set to 'reactor'. Can be called via bgf_plot when 'type = "relProduction"' or 'type = "all"'. In the later case, the plot is stored in a list with the label 'rel_production_curve'

The function plot_netProduct_by_Layout plots mean net gas curves per layout. It will extract 'net_product' values from the BioGasData-layer and calculates a mean for each 'Layout' specified in the metaData-layer at each 'time' before drawing the line plot.

Can be called via bgf_plot when 'type = "netProduct"' or 'type = "all"'. In the later case, the plot is stored in a list with the label 'net_product_curve'.

The function colplot_yield produces a col plot with reactor layouts on the x-axis and mean 'yield' values per layout on the y-axis. It can be used if a yield summary was transferred to the metaData-layer using summarize_yield. It will generate a column-plot with reactor layouts on the x-axis and mean yield values per layout on the y-axis. With the default settings, fermentations that are marked as 'Excluded' in the metaData-layer will not be included in the plot. The standard deviation around the mean value will be calculated and drawn as an errorbar if possible.

Can be called via bgf_plot when 'type = "yield_col"' or 'type = "all"'. In the later case, the plot is stored in a list with the label 'yield_col'.

The function boxplot_yield produces a box plot with reactor layouts on the x-axis and and 'yield' values per layout on the y-axis. The argument 'timep' can be used to specify how many observations will be used to draw the boxes. In the default setting, 'all', all available observations for a layout will be used. Alternatively, to select the final observations 'timep = "max"' can be set. Furthermore any numeric that matches a value in the 'time' column of the BioGasData-layer can be passed to 'timep' to select the specific 'yield' value at that time.

Can be called via bgf_plot when 'type = "yield_box"' or 'type = "all"'. In the later case, the plot is stored in a list with the label 'yield_box'.

Value

either a single ggplot2 object or a list of ggplot2 objects

Examples

# create an example BGF
myBGF <- from_AMPTSV2_report(
        ReactorLayout = c("2*Meso","Cellulose","2*S1 ctrl","2*S1 7d","2*S1 4d",
                          "2*S2 ctrl","2*S2 4d","2*S2 6d"),
        BlankLabel = "Meso",
        name = "myBGF",
        ProcessTemp = 40,
        InocToSubRatio = 2,
        path = base::system.file("extdata","AMPTSV2.csv",package = "bgfanalyzer"))


# generate all plots for the BGF
Plots <- bgf_plot(myBGF)

# print 'product' curve
if(interactive()) Plots[["product_curve"]]

# print 'net product' curve
if(interactive()) Plots[["net_product_curve"]]

# print 'production' curve
if(interactive()) Plots[["production_curve"]]

# print 'relative production' curve
if(interactive()) Plots[["rel_production_curve"]]

# print 'yield' colplot
if(interactive()) Plots[["yield_col"]]

# print 'yield' boxplot
if(interactive()) Plots[["yield_box"]]


# in the following examples the same plots are produced by plot_curve and the respective wrappers
# plot 'product' curve
plot_curve(
        x = myBGF,
        what = product,
        color = reactor,
        ylab = "raw exaust gas volume",
        xlab = paste0("observation time [",myBGF$ExpParam$timeScale,"]"))
if(interactive()) plot_product_curve(myBGF)
if(interactive()) bgf_plot(myBGF,type="product")

# plot 'production' curve
plot_curve(
        x = myBGF,
        what = production,
        color = reactor,
        ylab = "raw exaust gas flow",
        xlab = paste0("observation time [",myBGF$ExpParam$timeScale,"s]"))
if(interactive()) plot_production_curve(myBGF)
if(interactive()) bgf_plot(myBGF,type="production")

# plot 'rel_production' curve(s)
plot_curve(
        x = myBGF,
        what = rel_production,
        color = reactor,
        ylab = "remaining gas production [%]",
        xlab = paste0("observation time [",myBGF$ExpParam$timeScale,"s]"))
if(interactive()) plot_rel_production_curve(myBGF)
# Note: this curve is inverted so it starts at 100 %

if(interactive()) bgf_plot(myBGF,type="relProduction")

# plot mean net product by reactor layout
plot_netProduct_by_Layout(myBGF)

# create a col plot of the yield
colplot_yield(myBGF)
if(interactive()) bgf_plot(myBGF,type="yield_col")

# create a box plot of the 'yield'
boxplot_yield(myBGF)
if(interactive()) bgf_plot(myBGF,type="yield_box")

# create a box plot of the final 'yield'
boxplot_yield(myBGF,timep="max")
if(interactive()) bgf_plot(myBGF,type="yield_box",timep="max")


bgfanalyzer documentation built on Sept. 26, 2026, 5:07 p.m.