Repository navigation
Expand file tree
/
Copy pathdual_inlet.Rmd
More file actions
140 lines (111 loc) · 4.74 KB
/
Copy pathdual_inlet.Rmd
File metadata and controls
140 lines (111 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
---
title: "Dual Inlet Examples"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Dual Inlet Examples}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
# Introduction
Isoprocessor supports several plotting and data conversion functions specifically for dual inlet data. This vignette shows some of the functionality for dual inlet files read by the [isoreader package](http://isoprocessor.isoverse.org) (see the [corresponding vignette](http://isoreader.isoverse.org/articles/dual_inlet.html) for details on data retrieval, storage and export).
```{r, warning=FALSE, message=FALSE}
# load isoreader and isoprocessor packages
library(isoreader)
library(isoprocessor)
```
# Reading files
```{r}
# read dual inlet examples provided by the isoreader package
di_files <-
iso_read_dual_inlet(
iso_get_reader_example("dual_inlet_example.did"),
iso_get_reader_example("dual_inlet_example.caf")
)
```
# Visualization
Plotting the raw data can be done either with the generic `iso_plot_raw_data()` function for a simple plot with default parameters, or directly using the dual inlet specific `iso_plot_dual_inlet_data()`:
```{r "all_data", fig.width = 12, fig.asp = 0.8}
iso_plot_dual_inlet_data(di_files)
```
All customization options are described in the function help (`?iso_plot_dual_inlet_data`) and include, for example, plotting only a specific subset of masses:
```{r "select_masses", fig.width = 10, fig.asp = 0.3}
# plot just masses 44 and 45
iso_plot_dual_inlet_data(
di_files,
data = c("44", "45")
)
```
# Isotope ratios
For dual inlet applications isotope ratios calculated using the recorded ion intensities are typically of primary interest. For this purpose, isoprocessor provides a dynamic ratio calculation function (`iso_calculate_ratios()`) that accepts any combination of masses, here demonstrated for several different ratios. In this context, another useful customization option of the plotting function is the option to adjust plot aesthetics such as color, shape, and paneling:
```{r "ratios", fig.width = 8, fig.asp = 1}
di_files <-
di_files %>%
# calculate 46/44 and 45/44 ratios
iso_calculate_ratios(ratios = c("46/44", "45/44"))
iso_plot_dual_inlet_data(
di_files,
# visualize ratios
data = c("45/44", "46/44"),
# panel the ratios vs. type (standard/sample)
panel = data ~ type,
# color by the file info stored in Identifier 1
color = `Identifier 1`
)
```
# Deltas
In addition, isoprocessor provides a dynamic raw delta calculation function (`iso_calculate_deltas()`) that calculates direct or bracketed sample-standard delta values as described in the function help. See code below for a few examples:
```{r "deltas", fig.width = 8, fig.asp = 0.5}
di_files <-
di_files %>%
# calculate 46/44 and 45/44 deltas
iso_calculate_deltas(deltas = c("d46/44", "d45/44"),
bracket = TRUE, in_permil = TRUE)
iso_plot_dual_inlet_data(
di_files,
# visualize deltas together with one of the ratios
data = c("45/44", "d45/44", "d46/44"),
# color by the file info stored in Identifier 1
color = `Identifier 1`
)
```
# Signal conversion
Isoprocessor can convert between different signal units. This is particularly useful for comparing data files from different mass specs that record primary signals differentally. In dual inlet applications, this is typically less important than in continuous flow because data is usually visualized as ratios right away. However, occassionally it can be of interest to examine the primary ion currents.
```{r "signal_conversion", fig.width = 10, fig.asp = 0.3}
di_files$dual_inlet_example.caf %>%
# convert all signals to nano ampere
iso_convert_signals(to = "pA") %>%
# plot primary ion currents
iso_plot_dual_inlet_data(
data = c("45", "47", "48"),
color = type
)
```
# Plot styling
Since all isoprocessor plots are standard [ggplot](http://ggplot2.tidyverse.org/) objects, they can be modified with any ggplot commands. For example to add a horizontal line (using [dplyr](http://dplyr.tidyverse.org/) for the calculations) and modify the themes:
```{r "plot styling", message=FALSE, fig.width = 8, fig.asp = 0.7}
library(ggplot2)
# replot
iso_plot_dual_inlet_data(
di_files,
data = "45/44",
panel = type ~ `Identifier 1`,
color = `Identifier 1`
) +
# add horizontal line indicating the averages (using a ggplot geom)
geom_hline(
data = function(df) {
df %>%
dplyr::group_by(`Identifier 1`, type, data) %>%
dplyr::summarize(value = mean(value))
},
mapping = aes(yintercept = value)) +
# modify plot styling (ggplot functionality)
theme(text = element_text(size = 20))
```