MixSIAR results- Likely to erode source, composite mixture
Author
Alex Koiter
Load Libraries
In [1]:
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.0 ✔ tibble 3.2.1
✔ lubridate 1.9.2 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(MixSIAR)
Fingerprints
In [2]:
fingerprints <-c("Li", "U", "Bi")
Load in data
In [3]:
geo_results <-read.csv(here::here("./notebooks/Geochemistry analysis - Copy 2.csv")) %>%pivot_longer(cols = Ag:Zr, names_to ="Fingerprint", values_to ="value") %>%filter(Fingerprint %in%c("Ag", "Al", "As","B","Ba","Be","Bi","Ca","Cd","Ce","Co", "Cr", "Cs", "Cu", "Fe", "Ga", "Hf", "Hg", "In", "K", "La", "Li", "Mg", "Mn", "Mo", "Nb", "Ni", "P", "Pb", "Rb", "S", "Sb", "Sc", "Se", "Sn", "Sr", "Te", "Th", "Tl", "U", "V", "Y", "Zn", "Zr")) %>%# excludes fingerprints that are below level of detection dplyr::select(-X) %>%# don't need this columnfilter(sample_design %in%c("Grid", "Transect", "Likely to erode")) col_results <-read.csv(here::here("./notebooks/final results revised.csv")) %>%pivot_longer(cols = X:B, names_to ="Fingerprint", values_to ="value") %>% dplyr::select(-X.1) %>%# don't need this columnfilter(sample_design %in%c("Grid", "Transect", "Likely to erode")) %>%mutate(Fingerprint =paste0(Fingerprint, "_col")) # appended _col as some of the colour coefficients have the same id eg Boron = B and Blue also = B# Bind data setsresults <- geo_results %>%bind_rows(col_results) %>%filter(Fingerprint %in% fingerprints)
Virtual mixtures
In [4]:
proportions <-seq(0, 1, 0.05)mixtures <- results %>%filter(sample_design %in%c("Grid", "Likely to erode")) %>%# excluded transects as the transects are contained with in the grid this gives us all unique samples group_by(Fingerprint, site) %>%summarise(avg =mean(value)) %>%pivot_wider(names_from = site, values_from = avg) %>%mutate(mix_ag =map(Agriculture, ~.x * (1- proportions)),mix_forest =map(Forest, ~.x * proportions)) %>%group_by(Fingerprint, Agriculture, Forest) %>%summarize(mix =map2(mix_ag, mix_forest, ~data.frame(mix = .x + .y, prop_forest = proportions))) %>%unnest(mix) %>%pivot_wider(id_cols = prop_forest, names_from = Fingerprint, values_from = mix) %>%nest(.by = prop_forest) %>%mutate(path = here::here(paste0("./notebooks/Mixtures_all_likely/", prop_forest, ".csv")))
`summarise()` has grouped output by 'Fingerprint'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'Fingerprint', 'Agriculture'. You can
override using the `.groups` argument.