# Flow Injection

    # load libraries
    library(isoorbi) # for Orbitrap functions
    library(dplyr) # for data wrangling
    library(ggplot2) # for data visualization

# Data

## Load data

    # load and process data
    data <-
      # load file included in isoorbi package
      system.file(package = "isoorbi", "extdata", "testfile_flow.isox") |>
      orbi_read_isox() |>
      orbi_simplify_isox() |>
      # define data block where signal is stable (plateau)
      orbi_define_block_for_flow_injection(start_time.min = 0.1, end_time.min = 0.9) |>
      # flag extreme TICxIT values
      orbi_flag_outliers(agc_fold_cutoff = 2)

    [32m✔[39m [38;5;249m[231ms][39m [1morbi_read_isox()[22m loaded 6449 peaks for 1 compound ([32mHSO4-[39m) with 5
    isotopocules ([32mM0[39m, [32m33S[39m, [32m17O[39m, [32m34S[39m, and [32m18O[39m) from [34mtestfile_flow.isox[39m

    [32m✔[39m [38;5;249m[2ms][39m [1morbi_simplify_isox()[22m kept columns [32mfilepath[39m, [32mfilename[39m, [32mscan.no[39m,
    [32mtime.min[39m, [32mcompound[39m, [32misotopocule[39m, [32mions.incremental[39m, [32mtic[39m, and [32mit.ms[39m

    [32m✔[39m [38;5;249m[12ms][39m [1morbi_define_block_for_flow_injection()[22m added a new block (0.1 to 0.9
    min) to 3 files

    [32m✔[39m [38;5;249m[8ms][39m [1morbi_flag_outliers()[22m confirmed that none of the 1290 scans are [33moutliers[39m
    based on [32m2 fold AGC cutoff[39m, i.e. based on [3mscans below 1/2 and above 2 times the[23m
    [3maverage number of ions [32mtic[39m * [32mit.ms[39m in the Orbitrap analyzer[23m, in 6 data groups
    (based on [32mfilename[39m, [32mblock[39m, and [32msegment[39m)

# Calculations

## Ratios

    # basepeak & ratios
    data_w_basepeak <-
      data |>
      orbi_define_basepeak("M0")

    [32m✔[39m [38;5;249m[51ms][39m [1morbi_define_basepeak()[22m set [32mM0[39m as the ratio denominator and calculated
    5.16k [32mratio[39m values for 4 isotopocules ([32m33S[39m, [32m17O[39m, [32m34S[39m, and [32m18O[39m)

    # ratio summaries
    data_summary <-
      data_w_basepeak |>
      orbi_summarize_results(ratio_method = "sum")

    [32m✔[39m [38;5;249m[26ms][39m [1morbi_summarize_results()[22m summarized ratios from 4.14k peak ([3mexcluding[23m
    0 flagged peaks; [3mexcluding[23m 1.02k unused peaks) using the [1m[3msum[23m[22m method and
    grouping the data by [32mfilename[39m, [32mcompound[39m, [32mbasepeak[39m, [32misotopocule[39m, [32mblock[39m,
    [32msample_name[39m, [32msegment[39m, [32mdata_group[39m, and [32mdata_type[39m

# Figures

## Visualize data

    orbi_plot_raw_data(data, y = ions.incremental, y_scale = "log")

Ions of isotopocules in time

## Raw ratios

    data_w_basepeak |> orbi_plot_raw_data(y = ratio)

Isotopocule ratios vs M0

## Ratios for 18O

    fig <-
      data_summary |>
      filter(isotopocule == "18O") |>
      # plot
      ggplot() +
      aes(
        x = filename,
        y = ratio, ymin = ratio - ratio_sem, ymax = ratio + ratio_sem,
        color = filename, shape = filename
      ) +
      geom_pointrange() +
      scale_color_brewer(palette = "Dark2") +
      # theme definitions
      theme_bw() +
      theme(
        text = element_text(size = 16),
        panel.grid = element_blank()
      ) +
      # labels
      labs(
        y = expression("ratio ("^18*O/M0*")")
      )
    fig

Isotopocule ratios 18O vs M0