knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.align = "center"
)
# packages
library(elco)
library(magrittr)
library(ggplot2)
library(dplyr)
library(tidyr)

Introduction

This is the script to (1) import and check raw EA-IRMS data, and (2) perform correction of raw measured EA-IRMS data (correction of isotope signatures and element contents) in case of signal area mismatches between standards and samples.

Data import and reformatting

# data import
d <- 
  list.files("./../raw_data/", full.names = TRUE, pattern = ".csv$") %>%
  elco::elco_irms_import_csv()

# change sample labels of standards to match the labels used by elco (elco::irms_standards)
d$sample_label[d$sample_label == "BBOT_CN."] <- "BBOT"
# define figure heights
fig_height1 <- 5 * (length(unique(d$file_id))) / 3
fig_height2 <- 3 * (length(unique(d$file_id))) / 3

Checks

Compare signal areas of standards and samples

If the signal area for the samples differs clearly from those of the standards, especially BBOT, it is very likely that there is a bias in the measured isotope signatures and element contents.

d %>%
  dplyr::mutate(
    standard = purrr::map_lgl(d$sample_label, function(x) x %in% elco::irms_standards$standard_name),
    sample_label = factor(ifelse(standard, sample_label, ifelse(sample_label == "bla", "Blank", "Sample")), levels = c(elco::irms_standards$standard_name, "Sample", "Blank"))
  ) %>%
  tidyr::pivot_longer(cols = dplyr::all_of(c("13C_area", "15N_area")),
                      names_to = "isotope",
                      values_to = "signal_area") %>%
  ggplot(aes(x = sample_label, y = signal_area)) +
  geom_point() + 
  facet_grid(file_id ~ isotope, scales = "free_x") +
  coord_flip() +
  scale_y_log10() +
  labs(x = "Signal area", y = "Standard/sample")

Isotope signatures of standards

If there is a large difference between the median measured isotope signature and the known isotope signature for a standard, (especially one with similar signal area, see the previous plot), it is very likely that isotope signatures of samples are biased, too.

  d %>%
  elco::elco_irms_extract_standards() %>%
  tidyr::pivot_longer(cols = dplyr::all_of(c("13C", "15N")),
                      names_to = "isotope",
                      values_to = "isotope_signature") %>%
  ggplot(aes(x = sample_label, y = isotope_signature)) +
  geom_boxplot() +
  geom_point(data = 
               elco::irms_standards %>%
               dplyr::filter(standard_name %in% d$sample_label) %>%
               dplyr::rename(sample_label = standard_name) %>% 
               tidyr::pivot_longer(cols = dplyr::all_of(c("13C", "15N")),
                                   names_to = "isotope",
                                   values_to = "isotope_signature"), 
             mapping =  aes(x = sample_label, y = isotope_signature),
             colour = "red") +
  facet_grid(file_id ~ isotope, scales = "free_x") +
  coord_flip() +
  labs(y = expression(Isotope~"signature ["*delta*"\u2030]"),
       x = "Standards")

Isotope signatures of standards over time

If there is a trend visible, the heuristic procedure used for the correction of isotope signatures (see below) may not provide the "best" correction because it does not consider this trend, but simply subtracts the median isotope signature of a certain standard.

  d %>%
  elco::elco_irms_extract_standards() %>%
  tidyr::pivot_longer(cols = dplyr::all_of(c("13C", "15N")),
                      names_to = "isotope",
                      values_to = "isotope_signature") %>%
  ggplot(aes(x = time, y = isotope_signature, colour = sample_label)) +
  geom_hline(data = 
               elco::irms_standards %>%
               dplyr::filter(standard_name %in% d$sample_label) %>%
               dplyr::rename(sample_label = standard_name) %>% 
               tidyr::pivot_longer(cols = dplyr::all_of(c("13C", "15N")),
                                   names_to = "isotope",
                                   values_to = "isotope_signature"), 
             mapping =  aes(yintercept = isotope_signature, colour = sample_label),
             linetype = 2) +
  geom_smooth(se = FALSE, method = "lm") +
  geom_point() +
  facet_wrap(isotope ~ file_id, scales = "free") +
  labs(y = expression(Isotope~"signature ["*delta*"\u2030]"),
       x = "Time") +
  guides(colour = guide_legend(title = "Standard")) +
  theme(legend.position = "bottom")

Element contents of standards

If there is a large difference between the median measured element content and the known element content for a standard, (especially one with similar signal area, see the previous plot), it is very likely that isotope signatures of samples are biased, too.

d %>%
  elco::elco_irms_extract_standards() %>%
  dplyr::mutate(
    C = elco::elco_drop_elco(C),
    N = elco::elco_drop_elco(N),
  ) %>%
  tidyr::pivot_longer(cols = dplyr::all_of(c("C", "N")),
                      names_to = "element",
                      values_to = "mass_fraction") %>%
  ggplot(aes(x = sample_label, y = as.numeric(mass_fraction))) +
  geom_boxplot() +
  geom_point(data = 
               elco::irms_standards %>%
               dplyr::filter(standard_name %in% d$sample_label) %>%
               dplyr::rename(sample_label = standard_name) %>% 
               dplyr::mutate(
                 C = elco::elco_drop_elco(C),
                 N = elco::elco_drop_elco(N),
               ) %>%
               tidyr::pivot_longer(cols = dplyr::all_of(c("C", "N")),
                                   names_to = "element",
                                   values_to = "mass_fraction"), 
             mapping =  aes(x = sample_label, y = as.numeric(mass_fraction)),
             colour = "red") +
  facet_grid(file_id ~ element, scales = "free_x") +
  coord_flip() +
  labs(y = "Mass fraction",
       x = "Standards")

Element contents of standards over time

If there is a trend visible, the heuristic procedure used for the correction of isotope signatures (see below) may not provide the "best" correction because it does not consider this trend, but simply subtracts the median isotope signature of a certain standard.

  d %>%
  elco::elco_irms_extract_standards() %>%
  dplyr::mutate(
    C = elco::elco_drop_elco(C),
    N = elco::elco_drop_elco(N),
  ) %>%
  tidyr::pivot_longer(cols = dplyr::all_of(c("C", "N")),
                      names_to = "element",
                      values_to = "mass_fraction") %>%
  ggplot(aes(x = time, y = as.numeric(mass_fraction), colour = sample_label)) +
  geom_hline(data = 
               elco::irms_standards %>%
               dplyr::filter(standard_name %in% d$sample_label) %>%
               dplyr::rename(sample_label = standard_name) %>% 
               dplyr::mutate(
                 C = elco::elco_drop_elco(C),
                 N = elco::elco_drop_elco(N),
               ) %>%
               tidyr::pivot_longer(cols = dplyr::all_of(c("C", "N")),
                                   names_to = "element",
                                   values_to = "mass_fraction"), 
             mapping =  aes(yintercept = as.numeric(mass_fraction), colour = sample_label),
             linetype = 2) +
  geom_smooth(se = FALSE, method = "lm") +
  geom_point() +
  facet_wrap(element ~ file_id, scales = "free") +
  labs(y = "Mass fraction",
       x = "Time") +
  guides(colour = guide_legend(title = "Standard")) +
  theme(legend.position = "bottom")

Corrections

Isotope signatures

Correction of the $^{13}$C isotope signatures. The corrected values for the standards (especially those with a similar signal area as the samples) should match their known true values.

d %<>%
  elco::elco_irms_correct_isotopes(isotope = "13C", 
                                   ref = elco::irms_standards[irms_standards$standard_name == "BBOT", ],
                                   check = elco::irms_standards,
                                   t = 5, 
                                   by_file = TRUE, 
                                   plotit = TRUE)

Correction of the $^{15}$N isotope signatures. The corrected values for the standards (especially those with a similar signal area as the samples) should match their known true values.

d %<>%
  elco::elco_irms_correct_isotopes(isotope = "15N", 
                                   ref = elco::irms_standards[irms_standards$standard_name == "BBOT", ],
                                   check = elco::irms_standards,
                                   t = 5, 
                                   by_file = TRUE, 
                                   plotit = TRUE)

Element contents

Correction of the C content.

d %<>%
  elco::elco_irms_correct_elements(element = "C", 
                                   standards = elco::irms_standards$standard_name[elco::irms_standards$standard_name %in% d$sample_label], 
                                   by_file = TRUE, 
                                   plotit = TRUE)

Correction of the N content

d %<>%
  elco::elco_irms_correct_elements(element = "N", 
                                   standards = elco::irms_standards$standard_name[elco::irms_standards$standard_name %in% d$sample_label],
                                   by_file = TRUE, 
                                   plotit = TRUE)

License

Creative Commons License
This Rmarkdown template is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.

Title: Script to import and correct EA-IRMS isotope and element content data using elco.
Authors: Henning Teickner, Klaus-Holger Knorr
Date: 2020-08-05

Session info

sessionInfo()


henningte/elco documentation built on May 21, 2022, 6:56 p.m.