inst/doc/Introducing-BGF.R

## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----package schema,echo = FALSE,fig.height=7,fig.width=7---------------------
library(ggplot2)
# Setup and scale ####
dimensi=c(-25:60)
xlimit=c(-10,40)
ylimit=dimensi
basefont=4
fontstep=1
pointSize=40

Plot<-
# Generate an empty scaled plot ####
ggplot(mapping = aes(dimensi,dimensi))+
  scale_x_continuous(limits=xlimit)+
  #scale_y_continuous(limits=ylimit)+
  theme_void()+

  # R environment frame ####
  geom_rect(aes(xmin=8.5,xmax=37.5,ymin=7,ymax=33),color="steelblue",alpha=.0009,linewidth=1.5)+
  geom_text(mapping = aes(x=23,y=30,label="R programming language"),size=basefont,color="steelblue")+

  ## Box 1 bgfanalyzer ####
  geom_rect(aes(xmin=10,xmax=20,ymin=8,ymax=27),fill="orange",alpha=.02,color="black")+
  geom_text(mapping = aes(x=15,y=25,label="bgfanalyzer"),size=basefont,color="white")+

  geom_rect(aes(xmin=11,xmax=19,ymin=11,ymax=16),fill="orange",color="black")+
  geom_text(mapping = aes(x=15,y=13.7,label="data analysis/\nprocessing"),size=(basefont-fontstep),color="white")+

  geom_rect(aes(xmin=11,xmax=19,ymin=17,ymax=22),fill="orange",color="black")+
  geom_text(mapping = aes(x=15,y=19.7,label="experiment\ndesign"),size=(basefont-fontstep),color="white")+

  ## Box 2 other packages ####
  geom_rect(aes(xmin=26,xmax=36,ymin=8,ymax=27),fill="orange",alpha=.02,color="black")+
  geom_text(mapping = aes(x=31,y=25,label="other packages"),size=basefont,color="white")+

  geom_rect(aes(xmin=27,xmax=35,ymin=9,ymax=13),fill="orange",color="black")+
  geom_text(mapping = aes(x=31,y=11,label="keras3"),size=basefont,color="white")+


  geom_rect(aes(xmin=27,xmax=35,ymin=14,ymax=18),fill="orange",color="black")+
  geom_text(mapping = aes(x=31,y=16,label="phyloseq"),size=basefont,color="white")+

  geom_rect(aes(xmin=27,xmax=35,ymin=19,ymax=23),fill="orange",color="black")+
  geom_text(mapping = aes(x=31,y=21,label="Biogas"),size=basefont,color="white")+

  ## BGF_test ####
  geom_rect(aes(xmin=19.5,xmax=24.5,ymin=14,ymax=20),fill="black")+
  geom_polygon(mapping = aes(x=c(24,24,26.5),y=c(11.5,22.5,17)),fill="black")+
  geom_text(mapping = aes(x=22.7,y=17.1,label="BGF"),size=basefont,color="white")+

  # R Output
  geom_point(aes(x=17,y=-14),size=pointSize,color="darkgreen",alpha=.4)+
  geom_text(mapping = aes(x=17,y=-14,label="standardized data\nformats (.csv/ .RDS)"),size=(basefont-fontstep),color="white")+

  geom_point(aes(x=2,y=-14),size=pointSize,color="darkgreen",alpha=.4)+
  geom_text(mapping = aes(x=2,y=-14,label="Plots"),size=(basefont-fontstep),color="white")+

  geom_point(aes(x=32,y=-14),size=pointSize,color="darkgreen",alpha=.4)+
  geom_text(mapping = aes(x=32,y=-14,label="further analysis"),size=(basefont-fontstep),color="white")+

  # idea ####
  geom_rect(aes(xmin=-7,xmax=0,ymin=2,ymax=38),fill="darkblue",alpha=.02)+
  geom_text(mapping = aes(x=-3.5,y=19,label="Idea /\nResearch question"),size=basefont,color="white",angle=90)+

  # experiments ####
  geom_rect(aes(xmin=0,xmax=39,ymin=46,ymax=53),fill="darkgreen")+
  geom_text(mapping = aes(x=20,y=50,label="Lab experiments /\nSeries of fermentations"),size=basefont,color="white")+

  # connections ####
  ## Idea to bgfanalyzer ####
  geom_line(mapping = aes(x=c(-.5,10.5),y=c(19,19)),linewidth=2.3,arrow=arrow(angle = 30, length = unit(0.25, "inches"),
                                                                              ends = "both", type = "open"))+
  geom_text(aes(x=5,y=20.5,label="conception"),size=basefont)+

  ## Idea to Lab experiment ####
  geom_line(mapping = aes(x=c(-3.5,0.5),y=c(37.5,49.5)),linewidth=2.3,arrow=arrow(angle = 30, length = unit(0.25, "inches"),

                                                                                                                                ends = "last", type = "open"))+
  geom_text(aes(x=-3.,y=43.,label="leads to"),angle=55,size=basefont)+

  ## bgfanalyzer to Plots ####
  geom_line(mapping = aes(x=c(17,2),y=c(8.5,-9)),linewidth=2.3,arrow=arrow(angle = 30, length = unit(0.25, "inches"),
                                                                                ends = "first", type = "open"))+
  geom_text(aes(x=8.5,y=1.5,label="visualize"),angle=33,size=basefont)+

  ## bgfanalyzer to data formats ####
  geom_line(mapping = aes(x=c(17,17),y=c(8.5,-10)),linewidth=2.3,arrow=arrow(angle = 30, length = unit(0.25, "inches"),
                                                                                ends = "last", type = "open"))+
  geom_text(aes(x=17,y=-1.,label="data storage /\nexchange"),angle=90,size=basefont)+

  ## other packages to further analysis ####
  geom_line(mapping = aes(x=c(32,32),y=c(8.5,-9)),linewidth=2.3,arrow=arrow(angle = 30, length = unit(0.25, "inches"),
                                                                         ends = "last", type = "open"))+
  geom_text(aes(x=31,y=1.5,label="allows"),angle=90,size=basefont)+

  ## Lab experiments to bgfanalyzer ####
  geom_line(mapping = aes(x=c(12,12),y=c(46.5,26.5)),linewidth=2.3,arrow=arrow(angle = 30, length = unit(0.25, "inches"),
                                                                          ends = "last", type = "open"))+
  geom_text(aes(x=12,y=36.5,label="Input\ndata"),angle=90,size=basefont)


Plot

## ----first-BGF----------------------------------------------------------------
library(bgfanalyzer)

# create an example BGF with five fermentations having the reactor layout "A", "B", "C", "D", "E"
myBGF <- BGF(ReactorLayout = LETTERS[1:5])

# inspect the BGF
myBGF


## ----a named-BGF--------------------------------------------------------------
# create a named BGF by specifying the 'name' argument in BGF()
namedBGF <- BGF(ReactorLayout = paste0("2*",LETTERS[1:5]),
                name = "named BGF")

# inspect namedBGF
namedBGF

## ----re-naming-BGF------------------------------------------------------------
# rename myBGF using alter_whatever()
myBGF <- alter_whatever(myBGF,
                        layer = "ExpParam",
                        what = "name",
                        value = "new name")

# rename namedBGF using base syntax
namedBGF$ExpParam$name <- "new name"

# do myBGF and namedBGF have the same name now?
myBGF$ExpParam$name == namedBGF$ExpParam$name

# inspect renaming results
get_whatever(myBGF,
             layer = "ExpParam",
             what = "name")

# or
namedBGF$ExpParam$name

## ----inspect-ExpParam---------------------------------------------------------

# list 'ExpParam'-layers of both BGF's
# myBGF
myBGF$ExpParam

# namedBGF
namedBGF$ExpParam


## ----inspect-metaData---------------------------------------------------------
# list 'metaData'-layers 
# myBGF
myBGF$metaData

# namedBGF
namedBGF$metaData


## ----inspect-BioGasData-------------------------------------------------------
# list 'BioGasData'-layers
# myBGF
myBGF$BioGasData

# namedBGF
namedBGF$BioGasData


## ----updated-BioGasData-------------------------------------------------------
# remove empty columns in 'BioGasData'-layer
updatedBGF <- update_BGF(myBGF)

# inspect updated BGF
updatedBGF

# and its 'BioGasData'-layer
updatedBGF$BioGasData

## ----expBGF-------------------------------------------------------------------
# bind the example data set to an object
expBGF <- LabscaleBiogas

# rename it
expBGF <- alter_whatever(expBGF,"ExpParam","name","Example BGF")

# inspect it
expBGF

## ----plot-BGF,fig.width=7,fig.height=5----------------------------------------
# plot the 'BGF'
plot(expBGF)

## ----product-plot,fig.width=7,fig.height=5------------------------------------
# product plot
bgf_plot(expBGF,type = "product")

## ----net-product-plot,fig.width=7,fig.height=5--------------------------------
# net product by layout plot
bgf_plot(expBGF,type = "netProduct")

## ----get_reactorLayout--------------------------------------------------------
# print reactor layout of expBGF
get_ReactorLayout(expBGF,feedback = TRUE)

# check how many fermentations
length(get_ReactorLayout(expBGF))

# check how many distinct layouts exist in the BGF
length(levels(get_ReactorLayout(expBGF)))

## ----production-plot,fig.width=7,fig.height=5---------------------------------
# production plot
bgf_plot(expBGF,type = "production")

## ----rel-production-plot,fig.width=7,fig.height=5-----------------------------
# relative product plot
bgf_plot(expBGF,type = "relProduction")

## ----yield-col-plot,fig.width=7,fig.height=5----------------------------------
# yield col plot
bgf_plot(expBGF,type = "yield_col")

## ----yield-box-plot,fig.width=7,fig.height=5----------------------------------
# yield box plot
bgf_plot(expBGF,type = "yield_box")

Try the bgfanalyzer package in your browser

Any scripts or data that you put into this service are public.

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