\documentclass[]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
\else % if luatex or xelatex
  \ifxetex
    \usepackage{mathspec}
  \else
    \usepackage{fontspec}
  \fi
  \defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\fi
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage[margin=1in]{geometry}
\usepackage{hyperref}
\hypersetup{unicode=true,
            pdftitle={MS1-HRMS-Extractor.R},
            pdfauthor={Admin},
            pdfborder={0 0 0},
            breaklinks=true}
\urlstyle{same}  % don't use monospace font for urls
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{0}
% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi

%%% Use protect on footnotes to avoid problems with footnotes in titles
\let\rmarkdownfootnote\footnote%
\def\footnote{\protect\rmarkdownfootnote}

%%% Change title format to be more compact
\usepackage{titling}

% Create subtitle command for use in maketitle
\newcommand{\subtitle}[1]{
  \posttitle{
    \begin{center}\large#1\end{center}
    }
}

\setlength{\droptitle}{-2em}

  \title{MS1-HRMS-Extractor.R}
    \pretitle{\vspace{\droptitle}\centering\huge}
  \posttitle{\par}
    \author{Admin}
    \preauthor{\centering\large\emph}
  \postauthor{\par}
      \predate{\centering\large\emph}
  \postdate{\par}
    \date{Tue Jan 21 13:22:40 2020}


\begin{document}
\maketitle

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{require}\NormalTok{(}\StringTok{"readxl"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Loading required package: readxl
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{require}\NormalTok{(}\StringTok{"gridExtra"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Loading required package: gridExtra
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{require}\NormalTok{(}\StringTok{"dplyr"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Loading required package: dplyr
\end{verbatim}

\begin{verbatim}
## 
## Attaching package: 'dplyr'
\end{verbatim}

\begin{verbatim}
## The following object is masked from 'package:gridExtra':
## 
##     combine
\end{verbatim}

\begin{verbatim}
## The following objects are masked from 'package:stats':
## 
##     filter, lag
\end{verbatim}

\begin{verbatim}
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{require}\NormalTok{(}\StringTok{"reshape2"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Loading required package: reshape2
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{require}\NormalTok{(}\StringTok{"grid"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Loading required package: grid
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{require}\NormalTok{(}\StringTok{"tidyverse"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Loading required package: tidyverse
\end{verbatim}

\begin{verbatim}
## -- Attaching packages ------------------------------------------------------------------------------------------------------------ tidyverse 1.2.1 --
\end{verbatim}

\begin{verbatim}
## v ggplot2 3.2.1     v readr   1.1.1
## v tibble  2.1.3     v purrr   0.2.5
## v tidyr   0.8.2     v stringr 1.3.1
## v ggplot2 3.2.1     v forcats 0.3.0
\end{verbatim}

\begin{verbatim}
## -- Conflicts --------------------------------------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::combine() masks gridExtra::combine()
## x dplyr::filter()  masks stats::filter()
## x dplyr::lag()     masks stats::lag()
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{require}\NormalTok{(}\StringTok{"magrittr"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Loading required package: magrittr
\end{verbatim}

\begin{verbatim}
## 
## Attaching package: 'magrittr'
\end{verbatim}

\begin{verbatim}
## The following object is masked from 'package:purrr':
## 
##     set_names
\end{verbatim}

\begin{verbatim}
## The following object is masked from 'package:tidyr':
## 
##     extract
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#         When using this code data paths must be defined.}
\CommentTok{#         There are two options:}
\CommentTok{#         1.) via Rstudio Session -> Set Working Directory -> To Source File Location}
\CommentTok{#         This allows working without changing data paths.}
\CommentTok{#         Store sequence .xlsx file in folder ~Sequences/}
\CommentTok{#         Store database .xlsx file in folder ~Database/}
\CommentTok{#         Store spectra files in folder ~Spectra/}
\CommentTok{#         2.) if using data paths which are not directly placed in Source File location}
\CommentTok{#         define all paths individually}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#         Reading an .xlsx file that contains the information about target analytes and their species}
\CommentTok{#           Each row contains an information about only one species per compound. For instance, if the target analyte}
\CommentTok{#         forms three species during electrospray ionization - 3 rows are necessary.}
\CommentTok{#         }
\CommentTok{#         The first sheet contains the following columns: }
\CommentTok{#             Formula - molecular formula e.g. "C17H18F1N3O3"}
\CommentTok{#             Polarity - electrospray polarity: "POSITIVE"}
\CommentTok{#             Species - if Polarity is "POSITIVE", then}
\CommentTok{#                                 "[M+H]+", "[M+NH4]+", "[M+Na]+", "[M+K]+", "[M+CH3OH+H]+", "[2M+H]+" or "[M+2H]+".}
\CommentTok{#             Hierarchy - a number from 1-7, which corresponds to the order of species:}
\CommentTok{#                                 1:[M+H]+, 2:[M+NH4]+, 3:[M+Na]+, 4:[M+K]+, 5:[M+CH3OH+H]+, 6:[2M+H]+, 7:[M+2H]+}
\CommentTok{#             mz1 - theoretical m/z value of the most abundant ion}
\CommentTok{#             mz2 - theoretical m/z value of second most abundant ion}
\CommentTok{#             Q2/Q1 - theoretical ratio between mz2/mz1}
\CommentTok{#             Class - compound class, e.g. "Quinolones"}
\CommentTok{#             Compound - name of the compound e.g. "Ciprofloxacin"}
\CommentTok{#}
\CommentTok{#           For example, }
\CommentTok{#           Formula       | Polarity  | Species | Hierarchy |      mz1      |     mz2     |    Q2/Q1     |     Class    |   Compound      | }
\CommentTok{#  1st row: C17H18F1N3O3    | POSITIVE  | [M+H]+    |     1     |  332.1404961  | 333.1438569   |  18.5589575    |  Quinolone   | Ciprofloxacin | }
\CommentTok{#}
\CommentTok{#         The first row of the database should produce a data.frame, which is equal to this:}
\CommentTok{#         data.frame(Formula = "C17H18F1N3O3",}
\CommentTok{#         Polarity = "POSITIVE",}
\CommentTok{#         Species = "[M+H]+",}
\CommentTok{#         Hierarchy = 1,}
\CommentTok{#         mz1 = 332.1404961,}
\CommentTok{#         mz2 = 333.1438569,}
\CommentTok{#         Q2/Q1 = 18.5589575,}
\CommentTok{#         Class = "Quinolone",}
\CommentTok{#         Compound  = "Ciprofloxacin",row.names = FALSE,stringsAsFactors = FALSE)}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{database <-}\StringTok{ }\KeywordTok{read_xlsx}\NormalTok{(}\DataTypeTok{path =} \StringTok{"Database/Test_database.xlsx"}\NormalTok{,}\DataTypeTok{sheet =} \DecValTok{1}\NormalTok{)}
\NormalTok{database <-}\StringTok{ }\NormalTok{database }\OperatorTok{%>%}\StringTok{ }\KeywordTok{mutate_at}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\KeywordTok{colnames}\NormalTok{(database)[}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{3}\NormalTok{,}\DecValTok{8}\OperatorTok{:}\DecValTok{9}\NormalTok{)]),}\KeywordTok{funs}\NormalTok{(}\KeywordTok{factor}\NormalTok{(.)))}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Warning: funs() is soft deprecated as of dplyr 0.8.0
## please use list() instead
## 
##   # Before:
##   funs(name = f(.))
## 
##   # After: 
##   list(name = ~ f(.))
## This warning is displayed once per session.
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#         Reading an .xlsx file that contains the information about sample sequence}
\CommentTok{#         File contains 3 columns, each row contains information about one sample:}
\CommentTok{#         File.name - filename that contains MS1 spectra in positive mode}
\CommentTok{#         Sample.name - sample name}
\CommentTok{#         Path - data path (note: all "\textbackslash{}" must be substituted with "/")}
\CommentTok{#         For example,}
\CommentTok{#         }
\CommentTok{#         |   File.name    |  Sample.name   |              Path             |}
\CommentTok{#         |   Name_1-POS   |    Sample-1    |       d:/data/datapath/       |}
\CommentTok{#         }
\CommentTok{#         If anlyzing only one sample us lines 78-80, if using more samples  use line 77}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#sequence <- read_xlsx(path = "Sequences/Test_sequence.xlsx", sheet = 1)}
\NormalTok{sequence <-}\StringTok{ }\KeywordTok{data.frame}\NormalTok{(}\DataTypeTok{File.name =} \StringTok{"Test-spectra"}\NormalTok{,}
                       \DataTypeTok{Sample.name =} \StringTok{"This is a test"}\NormalTok{,}
                       \DataTypeTok{Path =} \StringTok{"Spectra/"}\NormalTok{,}\DataTypeTok{stringsAsFactors =} \OtherTok{FALSE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#         Define file extension and seperator}
\CommentTok{#         For example, ".csv", ".acs", ".txt" etc.}
\CommentTok{#         Delimiter is ussually TAB or ",", hence:}
\CommentTok{#         file.sep = "\textbackslash{}t", if using tab}
\CommentTok{#         file.sep = ",", if using comma}
\CommentTok{#         Other delimiters can also be defined}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{file.extension <-}\StringTok{ ".csv"}
\NormalTok{file.sep <-}\StringTok{ "}\CharTok{\textbackslash{}t}\StringTok{"}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#         Define path where the output files will be stored (note: all "\textbackslash{}" must be substituted with "/")}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{out.path <-}\StringTok{ "Output/"}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#         Define maximum error values for Q1 and Q2 (ppm) and ratio between Q2/Q1 (%)}
\CommentTok{#         For example, if maximum mass error is 5 ppm and Q2/Q1 ratio error is 20%, then:}
\CommentTok{#         Q1.delta.thr <- 5}
\CommentTok{#         Q2.delta.thr <- 5}
\CommentTok{#         Q2Q1.rato.error.thr <- 20}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{Q1.delta.thr <-}\StringTok{ }\DecValTok{5}
\NormalTok{Q2.delta.thr <-}\StringTok{ }\DecValTok{5}
\NormalTok{Q2Q1.rato.error.thr <-}\StringTok{ }\DecValTok{20}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#         RUN DATA PROCESSING}
\CommentTok{#         }\AlertTok{NOTE}\CommentTok{: All spectra files must contain at least two columns}
\CommentTok{#               The first column contains m/z values}
\CommentTok{#               The second column contains intesity values}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
  \ControlFlowTok{for}\NormalTok{ (i }\ControlFlowTok{in} \DecValTok{1}\OperatorTok{:}\KeywordTok{dim}\NormalTok{(sequence)[}\DecValTok{1}\NormalTok{])\{}
\NormalTok{  Index <-i}
\NormalTok{    \{}
    \CommentTok{#Assigning sample names (file names from DataAnalysis .asc exports) and data path where files are located}
    \CommentTok{#Add loop if more than 1 sample}
\NormalTok{    sample.name.pos <-}\StringTok{ }\NormalTok{sequence}\OperatorTok{$}\NormalTok{File.name[Index]}
\NormalTok{    data.path <-}\StringTok{ }\NormalTok{sequence}\OperatorTok{$}\NormalTok{Path[Index]}
\NormalTok{    sample.name <-}\StringTok{ }\NormalTok{sequence}\OperatorTok{$}\NormalTok{Sample.name[Index]}
\NormalTok{    \}}
    
    
    
    \CommentTok{#Reading raw MS files}
\NormalTok{    \{}
\NormalTok{    \{}
\NormalTok{    sample.pos <-}\StringTok{ }\KeywordTok{read.csv}\NormalTok{(}\DataTypeTok{file =} \KeywordTok{paste}\NormalTok{(data.path,sample.name.pos,file.extension, }\DataTypeTok{sep =} \StringTok{""}\NormalTok{),}\DataTypeTok{sep =}\NormalTok{ file.sep)}
\NormalTok{    sample.pos <-}\StringTok{ }\NormalTok{sample.pos[,}\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{]}
    \KeywordTok{colnames}\NormalTok{(sample.pos) <-}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"mz"}\NormalTok{,}\StringTok{"intensity"}\NormalTok{)}
\NormalTok{    \}}
    
    \CommentTok{#Preparing databases and results table for search algortihm}
\NormalTok{    \{}
\NormalTok{    results.pos <-}\StringTok{ }\KeywordTok{subset}\NormalTok{(database, Polarity }\OperatorTok{==}\StringTok{ "POSITIVE"}\NormalTok{)[}\OperatorTok{-}\DecValTok{2}\NormalTok{]}
\NormalTok{    database.pos <-}\StringTok{ }\KeywordTok{subset}\NormalTok{(database, Polarity }\OperatorTok{==}\StringTok{ "POSITIVE"}\NormalTok{)[}\OperatorTok{-}\DecValTok{2}\NormalTok{]}
\NormalTok{    add <-}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\DataTypeTok{data =} \OtherTok{NA}\NormalTok{, }\DataTypeTok{nrow =} \KeywordTok{as.numeric}\NormalTok{(}\KeywordTok{dim}\NormalTok{(results.pos)[}\DecValTok{1}\NormalTok{]), }\DataTypeTok{ncol =} \DecValTok{11}\NormalTok{,}\DataTypeTok{dimnames =} \KeywordTok{list}\NormalTok{(}\OtherTok{NULL}\NormalTok{,}\KeywordTok{c}\NormalTok{(}\StringTok{"Q1-measured, m/z"}\NormalTok{,}\StringTok{"Q1-Intesity, cps"}\NormalTok{,}\StringTok{"Q2-measured, m/z"}\NormalTok{,}\StringTok{"Q2-Intensity,cps"}\NormalTok{, }\StringTok{"ratio-Q2/Q1, %"}\NormalTok{, }\StringTok{"Error Q1, ppm"}\NormalTok{, }\StringTok{"Error Q2, ppm"}\NormalTok{, }\StringTok{"Error Q2/Q1, %"}\NormalTok{, }\StringTok{"Compliant"}\NormalTok{, }\StringTok{"Suspicious"}\NormalTok{,}\StringTok{"Only Q1 detected"}\NormalTok{)))}
\NormalTok{    results.pos <-}\StringTok{ }\KeywordTok{cbind}\NormalTok{(results.pos, add)}
    \KeywordTok{remove}\NormalTok{(add)}
\NormalTok{    detection.rate.pos <-}\StringTok{ }\NormalTok{results.pos[results.pos}\OperatorTok{$}\NormalTok{Hierarchy }\OperatorTok{==}\StringTok{ }\DecValTok{1}\NormalTok{,}\DecValTok{7}\OperatorTok{:}\DecValTok{8}\NormalTok{]}
\NormalTok{    add <-}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\DataTypeTok{data =} \OtherTok{NA}\NormalTok{, }\KeywordTok{as.numeric}\NormalTok{(}\KeywordTok{dim}\NormalTok{(detection.rate.pos)[}\DecValTok{1}\NormalTok{]), }\DataTypeTok{ncol =} \DecValTok{7}\NormalTok{,}\DataTypeTok{dimnames =} \KeywordTok{list}\NormalTok{(}\OtherTok{NULL}\NormalTok{,}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{,}\DecValTok{4}\NormalTok{,}\DecValTok{5}\NormalTok{,}\DecValTok{6}\NormalTok{,}\DecValTok{7}\NormalTok{)))}
\NormalTok{    detection.rate.pos <-}\StringTok{ }\KeywordTok{cbind}\NormalTok{(detection.rate.pos,add)}
    \KeywordTok{remove}\NormalTok{(add)}
\NormalTok{    \}}
    
    \CommentTok{#Running search algortihm for postive mode}
    \ControlFlowTok{for}\NormalTok{ (j }\ControlFlowTok{in} \DecValTok{1}\OperatorTok{:}\KeywordTok{as.numeric}\NormalTok{(}\KeywordTok{dim}\NormalTok{(database.pos)[}\DecValTok{1}\NormalTok{])) \{}
\NormalTok{      x1 <-}\StringTok{ }\KeywordTok{as.numeric}\NormalTok{(sample.pos[}\KeywordTok{which}\NormalTok{(}\KeywordTok{abs}\NormalTok{(database.pos}\OperatorTok{$}\NormalTok{mz1[j]}\OperatorTok{-}\NormalTok{sample.pos}\OperatorTok{$}\NormalTok{mz)}\OperatorTok{==}\KeywordTok{min}\NormalTok{(}\KeywordTok{abs}\NormalTok{(database.pos}\OperatorTok{$}\NormalTok{mz1[j]}\OperatorTok{-}\NormalTok{sample.pos}\OperatorTok{$}\NormalTok{mz))),}\DecValTok{1}\NormalTok{])}
\NormalTok{      i1 <-}\StringTok{ }\KeywordTok{as.numeric}\NormalTok{(sample.pos[}\KeywordTok{which}\NormalTok{(}\KeywordTok{abs}\NormalTok{(database.pos}\OperatorTok{$}\NormalTok{mz1[j]}\OperatorTok{-}\NormalTok{sample.pos}\OperatorTok{$}\NormalTok{mz)}\OperatorTok{==}\KeywordTok{min}\NormalTok{(}\KeywordTok{abs}\NormalTok{(database.pos}\OperatorTok{$}\NormalTok{mz1[j]}\OperatorTok{-}\NormalTok{sample.pos}\OperatorTok{$}\NormalTok{mz))),}\DecValTok{2}\NormalTok{])}
\NormalTok{      x2 <-}\StringTok{ }\KeywordTok{as.numeric}\NormalTok{(sample.pos[}\KeywordTok{which}\NormalTok{(}\KeywordTok{abs}\NormalTok{(database.pos}\OperatorTok{$}\NormalTok{mz2[j]}\OperatorTok{-}\NormalTok{sample.pos}\OperatorTok{$}\NormalTok{mz)}\OperatorTok{==}\KeywordTok{min}\NormalTok{(}\KeywordTok{abs}\NormalTok{(database.pos}\OperatorTok{$}\NormalTok{mz2[j]}\OperatorTok{-}\NormalTok{sample.pos}\OperatorTok{$}\NormalTok{mz))),}\DecValTok{1}\NormalTok{])}
\NormalTok{      i2 <-}\StringTok{ }\KeywordTok{as.numeric}\NormalTok{(sample.pos[}\KeywordTok{which}\NormalTok{(}\KeywordTok{abs}\NormalTok{(database.pos}\OperatorTok{$}\NormalTok{mz2[j]}\OperatorTok{-}\NormalTok{sample.pos}\OperatorTok{$}\NormalTok{mz)}\OperatorTok{==}\KeywordTok{min}\NormalTok{(}\KeywordTok{abs}\NormalTok{(database.pos}\OperatorTok{$}\NormalTok{mz2[j]}\OperatorTok{-}\NormalTok{sample.pos}\OperatorTok{$}\NormalTok{mz))),}\DecValTok{2}\NormalTok{])}
\NormalTok{      delta1 <-}\StringTok{ }\KeywordTok{abs}\NormalTok{(x1}\OperatorTok{-}\KeywordTok{as.numeric}\NormalTok{(database.pos}\OperatorTok{$}\NormalTok{mz1[j]))}\OperatorTok{/}\KeywordTok{as.numeric}\NormalTok{(database.pos}\OperatorTok{$}\NormalTok{mz1[j])}\OperatorTok{*}\DecValTok{1000000}
\NormalTok{      delta2 <-}\StringTok{ }\KeywordTok{abs}\NormalTok{(x2}\OperatorTok{-}\KeywordTok{as.numeric}\NormalTok{(database.pos}\OperatorTok{$}\NormalTok{mz2[j]))}\OperatorTok{/}\KeywordTok{as.numeric}\NormalTok{(database.pos}\OperatorTok{$}\NormalTok{mz2[j])}\OperatorTok{*}\DecValTok{1000000}
\NormalTok{      ratio <-}\StringTok{ }\NormalTok{i2}\OperatorTok{/}\NormalTok{i1}\OperatorTok{*}\DecValTok{100}
\NormalTok{      error_ratio <-}\StringTok{ }\KeywordTok{abs}\NormalTok{(database.pos}\OperatorTok{$}\StringTok{`}\DataTypeTok{Q2/Q1}\StringTok{`}\NormalTok{[j]}\OperatorTok{-}\NormalTok{ratio)}\OperatorTok{/}\NormalTok{database.pos}\OperatorTok{$}\StringTok{`}\DataTypeTok{Q2/Q1}\StringTok{`}\NormalTok{[j]}\OperatorTok{*}\DecValTok{100}
      \ControlFlowTok{if}\NormalTok{ ((delta1 }\OperatorTok{<}\StringTok{ }\NormalTok{Q1.delta.thr) }\OperatorTok{&&}\StringTok{ }\NormalTok{(delta2 }\OperatorTok{<}\StringTok{ }\NormalTok{Q2.delta.thr) }\OperatorTok{&&}\StringTok{ }\NormalTok{(error_ratio }\OperatorTok{<}\StringTok{ }\NormalTok{Q2Q1.rato.error.thr)) \{compliant <-}\StringTok{ }\OtherTok{TRUE}\NormalTok{\} }\ControlFlowTok{else}\NormalTok{ \{compliant <-}\StringTok{ }\OtherTok{FALSE}\NormalTok{\}}
      \ControlFlowTok{if}\NormalTok{ ((delta1 }\OperatorTok{<}\StringTok{ }\NormalTok{Q1.delta.thr) }\OperatorTok{&&}\StringTok{ }\NormalTok{(delta2 }\OperatorTok{<}\StringTok{ }\NormalTok{Q2.delta.thr) }\OperatorTok{&&}\StringTok{ }\NormalTok{(error_ratio }\OperatorTok{>}\StringTok{ }\NormalTok{Q2Q1.rato.error.thr) }\OperatorTok{&&}\StringTok{ }\NormalTok{(error_ratio }\OperatorTok{<}\StringTok{ }\DecValTok{100}\NormalTok{)) \{suspicious <-}\StringTok{ }\OtherTok{TRUE}\NormalTok{\} }\ControlFlowTok{else}\NormalTok{ \{suspicious <-}\StringTok{ }\OtherTok{FALSE}\NormalTok{\}}
      \ControlFlowTok{if}\NormalTok{ ((delta1 }\OperatorTok{<}\NormalTok{Q1.delta.thr) }\OperatorTok{&&}\StringTok{ }\NormalTok{(delta2 }\OperatorTok{>}\NormalTok{Q2.delta.thr)) \{only.q1 <-}\StringTok{ }\OtherTok{TRUE}\NormalTok{\} }\ControlFlowTok{else}\NormalTok{ \{only.q1 <-}\StringTok{ }\OtherTok{FALSE}\NormalTok{\}}
\NormalTok{      results.pos[j,}\DecValTok{9}\OperatorTok{:}\DecValTok{19}\NormalTok{] <-}\StringTok{ }\KeywordTok{c}\NormalTok{(x1,i1,x2,i2,ratio,delta1,delta2,error_ratio,}\KeywordTok{as.logical}\NormalTok{(compliant),}\KeywordTok{as.logical}\NormalTok{(suspicious),}\KeywordTok{as.logical}\NormalTok{(only.q1))}
      \ControlFlowTok{if}\NormalTok{ (compliant }\OperatorTok{==}\StringTok{ }\OtherTok{FALSE} \OperatorTok{&&}\StringTok{ }\NormalTok{suspicious }\OperatorTok{==}\StringTok{ }\OtherTok{FALSE} \OperatorTok{&}\StringTok{ }\NormalTok{only.q1 }\OperatorTok{==}\StringTok{ }\OtherTok{FALSE}\NormalTok{) \{results.pos[i,}\DecValTok{9}\OperatorTok{:}\DecValTok{16}\NormalTok{] <-}\StringTok{ }\OtherTok{NA}\NormalTok{\}}
      \KeywordTok{print}\NormalTok{(}\KeywordTok{paste}\NormalTok{(x1,}\StringTok{" un "}\NormalTok{,x2, }\DataTypeTok{sep=}\StringTok{""}\NormalTok{))}
      \KeywordTok{remove}\NormalTok{(x1,i1,x2,i2,ratio,delta1,delta2,error_ratio,compliant,suspicious,only.q1)}
\NormalTok{    \}}
    
    \CommentTok{#Reshaping results matrix}
\NormalTok{    \{}
\NormalTok{    results.pos}\OperatorTok{$}\NormalTok{Compliant <-}\StringTok{ }\KeywordTok{as.logical}\NormalTok{(results.pos}\OperatorTok{$}\NormalTok{Compliant)}
\NormalTok{    results.pos}\OperatorTok{$}\NormalTok{Suspicious <-}\StringTok{ }\KeywordTok{as.logical}\NormalTok{(results.pos}\OperatorTok{$}\NormalTok{Suspicious)}
\NormalTok{    results.pos}\OperatorTok{$}\StringTok{`}\DataTypeTok{Only Q1 detected}\StringTok{`}\NormalTok{ <-}\StringTok{ }\KeywordTok{as.logical}\NormalTok{(results.pos}\OperatorTok{$}\StringTok{`}\DataTypeTok{Only Q1 detected}\StringTok{`}\NormalTok{)}
\NormalTok{    results.pos.reshape<-}\StringTok{ }\KeywordTok{reshape}\NormalTok{(results.pos[}\KeywordTok{c}\NormalTok{(}\OperatorTok{-}\NormalTok{(}\DecValTok{3}\OperatorTok{:}\DecValTok{6}\NormalTok{),}\OperatorTok{-}\DecValTok{9}\NormalTok{,}\OperatorTok{-}\NormalTok{(}\DecValTok{11}\OperatorTok{:}\DecValTok{13}\NormalTok{))], }\DataTypeTok{idvar=}\KeywordTok{c}\NormalTok{(}\StringTok{"Compound"}\NormalTok{,}\StringTok{"Class"}\NormalTok{,}\StringTok{"Formula"}\NormalTok{),}\DataTypeTok{timevar =} \StringTok{"Species"}\NormalTok{, }\DataTypeTok{direction=}\StringTok{"wide"}\NormalTok{)}
\NormalTok{    results.pos.reshape2 <-}\StringTok{ }\NormalTok{results.pos}
\NormalTok{    results.pos.reshape2 <-}\StringTok{ }\NormalTok{results.pos.reshape2 }\OperatorTok{%>%}\StringTok{ }\KeywordTok{arrange}\NormalTok{(Hierarchy)}
\NormalTok{    \}}
    
    
    \CommentTok{#Write results to files (only compliant)}

    \KeywordTok{write.table}\NormalTok{(results.pos.reshape2, }\KeywordTok{paste}\NormalTok{(out.path, sample.name.pos,}\StringTok{".txt"}\NormalTok{,}\DataTypeTok{sep =} \StringTok{""}\NormalTok{), }\DataTypeTok{sep=}\StringTok{"}\CharTok{\textbackslash{}t}\StringTok{"}\NormalTok{,}\DataTypeTok{row.names =} \OtherTok{FALSE}\NormalTok{)}
\NormalTok{    \}   }
\NormalTok{  \}}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## [1] "332.1404961 un 333.1438569"
## [1] "349.1673944 un 350.1711061"
## [1] "354.1224407 un 355.1258024"
## [1] "366.2076413 un 366.2076413"
## [1] "365.20318 un 365.20318"
## [1] "719.336316 un 719.336316"
## [1] "181.0913976 un 181.0913976"
## [1] "360.1728768 un 361.1755199"
## [1] "377.1987226 un 378.2024647"
## [1] "378.2024647 un 387.1862862"
## [1] "388.1896543 un 388.1896543"
## [1] "388.1896543 un 388.1896543"
## [1] "719.336316 un 720.3393951"
## [1] "181.0913976 un 181.0913976"
## [1] "365.20318 un 366.2076413"
## [1] "378.2024647 un 387.1862862"
## [1] "387.1862862 un 388.1896543"
## [1] "388.1896543 un 388.1896543"
## [1] "388.1896543 un 388.1896543"
## [1] "720.3393951 un 720.3393951"
## [1] "181.0913976 un 181.0913976"
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#         Data visualization section}
\CommentTok{#         Can be used only for one sample at a time, hence cannot be run in sequence mode by loading an .xlsx file}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#         Visual data output}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#         Preparing data for plotting}
\NormalTok{\{}
\NormalTok{holder.pos <-}\StringTok{ }\KeywordTok{subset}\NormalTok{(results.pos.reshape,}\DataTypeTok{select =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\OperatorTok{:}\DecValTok{3}\NormalTok{,}\DecValTok{8}\OperatorTok{:}\DecValTok{10}\NormalTok{,}\DecValTok{15}\OperatorTok{:}\DecValTok{17}\NormalTok{,}\DecValTok{22}\OperatorTok{:}\DecValTok{24}\NormalTok{,}\DecValTok{29}\OperatorTok{:}\DecValTok{31}\NormalTok{,}\DecValTok{36}\OperatorTok{:}\DecValTok{38}\NormalTok{,}\DecValTok{43}\OperatorTok{:}\DecValTok{45}\NormalTok{,}\DecValTok{50}\OperatorTok{:}\DecValTok{52}\NormalTok{))}
\NormalTok{holder.pos[holder.pos}\OperatorTok{$}\NormalTok{Compound }\OperatorTok{==}\StringTok{ "Example"}\NormalTok{,}\KeywordTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{7}\NormalTok{,}\DecValTok{11}\NormalTok{)] <-}\StringTok{ }\KeywordTok{c}\NormalTok{(}\OtherTok{TRUE}\NormalTok{,}\OtherTok{TRUE}\NormalTok{,}\OtherTok{TRUE}\NormalTok{)}

\ControlFlowTok{for}\NormalTok{ (i }\ControlFlowTok{in} \KeywordTok{seq}\NormalTok{(}\DecValTok{3}\NormalTok{,}\KeywordTok{dim}\NormalTok{(holder.pos)[}\DecValTok{2}\NormalTok{], }\DataTypeTok{by =} \DecValTok{3}\NormalTok{)) \{}
\NormalTok{  holder.pos[(}\KeywordTok{dim}\NormalTok{(holder.pos)[}\DecValTok{2}\NormalTok{]}\OperatorTok{+}\DecValTok{1}\NormalTok{)] <-}\StringTok{ }\DecValTok{0}
  \ControlFlowTok{for}\NormalTok{ (j }\ControlFlowTok{in} \DecValTok{1}\OperatorTok{:}\KeywordTok{dim}\NormalTok{(holder.pos)[}\DecValTok{1}\NormalTok{])\{}
    \ControlFlowTok{if}\NormalTok{ (}\KeywordTok{is.na}\NormalTok{(holder.pos[j,i]) }\OperatorTok{==}\StringTok{ }\OtherTok{FALSE} \OperatorTok{&}\StringTok{ }\KeywordTok{is.na}\NormalTok{(holder.pos[j,i}\OperatorTok{+}\DecValTok{1}\NormalTok{]) }\OperatorTok{==}\StringTok{ }\OtherTok{FALSE} \OperatorTok{&}\StringTok{ }\KeywordTok{is.na}\NormalTok{(holder.pos[j,i}\OperatorTok{+}\DecValTok{2}\NormalTok{]) }\OperatorTok{==}\StringTok{ }\OtherTok{FALSE}\NormalTok{) \{}
      \ControlFlowTok{if}\NormalTok{ (holder.pos[j,i] }\OperatorTok{==}\StringTok{ }\OtherTok{TRUE}\NormalTok{) \{holder.pos[j,(}\KeywordTok{dim}\NormalTok{(holder.pos)[}\DecValTok{2}\NormalTok{])] <-}\StringTok{ }\DecValTok{3}\NormalTok{\}}
      \ControlFlowTok{if}\NormalTok{ (holder.pos[j,i}\OperatorTok{+}\DecValTok{1}\NormalTok{] }\OperatorTok{==}\StringTok{ }\OtherTok{TRUE}\NormalTok{) \{holder.pos[j,(}\KeywordTok{dim}\NormalTok{(holder.pos)[}\DecValTok{2}\NormalTok{])] <-}\StringTok{ }\DecValTok{2}\NormalTok{\}}
      \ControlFlowTok{if}\NormalTok{ (holder.pos[j,i}\OperatorTok{+}\DecValTok{2}\NormalTok{] }\OperatorTok{==}\StringTok{ }\OtherTok{TRUE}\NormalTok{) \{holder.pos[j,(}\KeywordTok{dim}\NormalTok{(holder.pos)[}\DecValTok{2}\NormalTok{])] <-}\StringTok{ }\DecValTok{1}\NormalTok{\}    }
\NormalTok{    \}}
\NormalTok{  \}}
\NormalTok{\}}
\NormalTok{\}}
\NormalTok{\{}
\NormalTok{heatmap.detected.pos <-}\StringTok{ }\KeywordTok{melt}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ holder.pos[}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{,}\DecValTok{24}\OperatorTok{:}\DecValTok{30}\NormalTok{)],}\DataTypeTok{measure.vars =} \KeywordTok{colnames}\NormalTok{(holder.pos[}\DecValTok{24}\OperatorTok{:}\DecValTok{30}\NormalTok{]),}\DataTypeTok{id.vars =} \KeywordTok{c}\NormalTok{(}\StringTok{"Class"}\NormalTok{,}\StringTok{"Compound"}\NormalTok{),}\DataTypeTok{variable.name =} \StringTok{"Species"}\NormalTok{)}
\KeywordTok{levels}\NormalTok{(heatmap.detected.pos}\OperatorTok{$}\NormalTok{Species) <-}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"[M+H]+"}\NormalTok{,}\StringTok{"[M+NH4]+"}\NormalTok{,}\StringTok{"[M+Na]+"}\NormalTok{,}\StringTok{"[M+K]+"}\NormalTok{,}\StringTok{"[M+CH3OH+H]+"}\NormalTok{,}\StringTok{"[2M+H]+"}\NormalTok{,}\StringTok{"[M+2H]+"}\NormalTok{)}
\KeywordTok{levels}\NormalTok{(heatmap.detected.pos}\OperatorTok{$}\NormalTok{Species) <-}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"1P"}\NormalTok{,}\StringTok{"2P"}\NormalTok{,}\StringTok{"3P"}\NormalTok{,}\StringTok{"4P"}\NormalTok{,}\StringTok{"5P"}\NormalTok{,}\StringTok{"6P"}\NormalTok{,}\StringTok{"7P"}\NormalTok{)}
\NormalTok{heatmap.detected <-}\StringTok{ }\NormalTok{heatmap.detected.pos}
\NormalTok{heatmap.detected}\OperatorTok{$}\NormalTok{value <-}\StringTok{ }\KeywordTok{as.factor}\NormalTok{(heatmap.detected}\OperatorTok{$}\NormalTok{value)}
\KeywordTok{factor}\NormalTok{(heatmap.detected}\OperatorTok{$}\NormalTok{value, }\DataTypeTok{levels =} \KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{))}
\NormalTok{colors <-}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"lightskyblue3"}\NormalTok{,}\StringTok{"palevioletred1"}\NormalTok{,}\StringTok{"yellow1"}\NormalTok{,}\StringTok{"olivedrab1"}\NormalTok{)}
\KeywordTok{names}\NormalTok{(colors) <-}\StringTok{ }\KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{)}
\NormalTok{\}}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#         An overall heatmap for detected species}
\CommentTok{#         1P:[M+H]+, 2P:[M+NH4]+, 3P:[M+Na]+, 4P:[M+K]+, 5P:[M+CH3OH+H]+, 6P:[2M+H]+, 7P:[M+2H]+}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{ggplot}\NormalTok{(heatmap.detected, }\KeywordTok{aes}\NormalTok{(Species, Compound, }\DataTypeTok{colour =}\NormalTok{ Class))}\OperatorTok{+}
\StringTok{    }\KeywordTok{geom_tile}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\DataTypeTok{fill =}\NormalTok{ value), }\DataTypeTok{colour =} \StringTok{"lightskyblue4"}\NormalTok{, }\DataTypeTok{size =} \FloatTok{0.1}\NormalTok{, }\DataTypeTok{stat =} \StringTok{"identity"}\NormalTok{, }\DataTypeTok{width =} \DecValTok{1}\NormalTok{, }\DataTypeTok{height =} \DecValTok{1}\NormalTok{)}\OperatorTok{+}
\StringTok{    }\KeywordTok{scale_fill_manual}\NormalTok{(}\DataTypeTok{values=}\NormalTok{ colors,}\DataTypeTok{labels =} \KeywordTok{c}\NormalTok{(}\StringTok{"Not detected"}\NormalTok{,}\StringTok{"Only Q1 detected"}\NormalTok{,}\StringTok{"Detected (ratio Q2/Q1 > 30%)"}\NormalTok{, }\StringTok{"Detected"}\NormalTok{))}\OperatorTok{+}
\StringTok{    }\CommentTok{#scale_fill_gradientn(guide = "legend",colours = c("lightskyblue3","olivedrab1"),values = c(0,1))+}
\StringTok{    }\KeywordTok{ggtitle}\NormalTok{(}\DataTypeTok{label =} \KeywordTok{paste}\NormalTok{(}\StringTok{"SAMPLE:"}\NormalTok{,sample.name))}\OperatorTok{+}
\StringTok{    }\KeywordTok{theme}\NormalTok{(}\DataTypeTok{panel.grid.major =} \KeywordTok{element_blank}\NormalTok{(),}
          \DataTypeTok{panel.border =} \KeywordTok{element_blank}\NormalTok{(),}
          \DataTypeTok{panel.background =} \KeywordTok{element_blank}\NormalTok{(),}
          \DataTypeTok{axis.ticks =} \KeywordTok{element_blank}\NormalTok{(),}
          \DataTypeTok{axis.text.x =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{7}\NormalTok{, }\DataTypeTok{vjust =} \FloatTok{0.5}\NormalTok{),}
          \DataTypeTok{axis.text.y =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{8}\NormalTok{),}
          \DataTypeTok{legend.title =} \KeywordTok{element_blank}\NormalTok{(),}
          \DataTypeTok{legend.position =} \StringTok{"top"}\NormalTok{, }
          \DataTypeTok{legend.spacing.x =} \KeywordTok{unit}\NormalTok{(}\FloatTok{0.1}\NormalTok{, }\StringTok{'cm'}\NormalTok{),}
          \DataTypeTok{legend.text =} \ControlFlowTok{if}\NormalTok{ (i }\OperatorTok{==}\StringTok{ }\DecValTok{3}\NormalTok{) \{}\KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{7}\NormalTok{)\} }\ControlFlowTok{else}\NormalTok{ \{}\KeywordTok{element_blank}\NormalTok{()\},}
          \DataTypeTok{legend.key.size =} \KeywordTok{unit}\NormalTok{(}\FloatTok{0.4}\NormalTok{, }\StringTok{'cm'}\NormalTok{),}
          \DataTypeTok{axis.title.y =} \KeywordTok{element_blank}\NormalTok{(),}
          \DataTypeTok{plot.title =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{10}\NormalTok{, }\DataTypeTok{face =} \StringTok{"bold"}\NormalTok{,}\DataTypeTok{hjust =} \DecValTok{0}\NormalTok{),}
          \DataTypeTok{axis.title.x =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size=}\DecValTok{7}\NormalTok{))}\OperatorTok{+}
\StringTok{    }\KeywordTok{geom_vline}\NormalTok{(}\DataTypeTok{xintercept =} \FloatTok{7.5}\NormalTok{, }\DataTypeTok{colour =} \StringTok{"white"}\NormalTok{, }\DataTypeTok{size =} \DecValTok{2}\NormalTok{)}\OperatorTok{+}
\StringTok{  }\KeywordTok{theme}\NormalTok{(}\DataTypeTok{strip.background =} \KeywordTok{element_rect}\NormalTok{(}\DataTypeTok{fill =} \StringTok{"deepskyblue4"}\NormalTok{), }\DataTypeTok{strip.text =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{face=}\StringTok{"bold"}\NormalTok{,}\DataTypeTok{colour =} \StringTok{"white"}\NormalTok{))}\OperatorTok{+}
\StringTok{  }\KeywordTok{facet_wrap}\NormalTok{(}\OperatorTok{~}\NormalTok{Class,}\DataTypeTok{nrow =} \DecValTok{2}\NormalTok{,}\DataTypeTok{scales =} \StringTok{"free_x"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\includegraphics{MS1-HRMS-Extractor_files/figure-latex/unnamed-chunk-21-1.pdf}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#           Q1 error plots}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{\{}
\NormalTok{holder.pos <-}\StringTok{ }\KeywordTok{subset}\NormalTok{(results.pos.reshape,}\DataTypeTok{select =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\OperatorTok{:}\DecValTok{3}\NormalTok{,}\DecValTok{5}\NormalTok{,}\DecValTok{12}\NormalTok{,}\DecValTok{19}\NormalTok{,}\DecValTok{26}\NormalTok{,}\DecValTok{33}\NormalTok{,}\DecValTok{40}\NormalTok{,}\DecValTok{47}\NormalTok{))}
\NormalTok{heatmap.q1.pos <-}\StringTok{ }\KeywordTok{melt}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ holder.pos[}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{,}\DecValTok{3}\OperatorTok{:}\DecValTok{9}\NormalTok{)],}\DataTypeTok{measure.vars =} \KeywordTok{colnames}\NormalTok{(holder.pos[}\DecValTok{3}\OperatorTok{:}\DecValTok{9}\NormalTok{]),}\DataTypeTok{id.vars =} \KeywordTok{c}\NormalTok{(}\StringTok{"Class"}\NormalTok{,}\StringTok{"Compound"}\NormalTok{),}\DataTypeTok{variable.name =} \StringTok{"Species"}\NormalTok{)}
\KeywordTok{levels}\NormalTok{(heatmap.q1.pos}\OperatorTok{$}\NormalTok{Species) <-}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"[M+H]+"}\NormalTok{,}\StringTok{"[M+NH4]+"}\NormalTok{,}\StringTok{"[M+Na]+"}\NormalTok{,}\StringTok{"[M+K]+"}\NormalTok{,}\StringTok{"[M+CH3OH+H]+"}\NormalTok{,}\StringTok{"[2M+H]+"}\NormalTok{,}\StringTok{"[M+2H]+"}\NormalTok{)}
\KeywordTok{levels}\NormalTok{(heatmap.q1.pos}\OperatorTok{$}\NormalTok{Species) <-}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"1P"}\NormalTok{,}\StringTok{"2P"}\NormalTok{,}\StringTok{"3P"}\NormalTok{,}\StringTok{"4P"}\NormalTok{,}\StringTok{"5P"}\NormalTok{,}\StringTok{"6P"}\NormalTok{,}\StringTok{"7P"}\NormalTok{)}
\NormalTok{heatmap.q1 <-}\StringTok{ }\NormalTok{heatmap.q1.pos}
\KeywordTok{colnames}\NormalTok{(heatmap.q1)[}\DecValTok{4}\NormalTok{] <-}\StringTok{ "Error"}
\NormalTok{\}}

\KeywordTok{ggplot}\NormalTok{(heatmap.q1, }\KeywordTok{aes}\NormalTok{(Species, Compound))}\OperatorTok{+}
\StringTok{      }\KeywordTok{geom_tile}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\DataTypeTok{fill =}\NormalTok{ Error), }\DataTypeTok{colour =} \StringTok{"lightskyblue4"}\NormalTok{, }\DataTypeTok{size =} \FloatTok{0.1}\NormalTok{, }\DataTypeTok{stat =} \StringTok{"identity"}\NormalTok{, }\DataTypeTok{width =} \DecValTok{1}\NormalTok{, }\DataTypeTok{height =} \DecValTok{1}\NormalTok{)}\OperatorTok{+}
\StringTok{      }\KeywordTok{scale_fill_gradientn}\NormalTok{(}\DataTypeTok{limits =} \KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,Q1.delta.thr),}\DataTypeTok{colours=} \KeywordTok{c}\NormalTok{(}\StringTok{"olivedrab1"}\NormalTok{,}\StringTok{"darkorange"}\NormalTok{,}\StringTok{"indianred1"}\NormalTok{),}\DataTypeTok{na.value =} \StringTok{"grey"}\NormalTok{,}\DataTypeTok{breaks=}\KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,Q1.delta.thr}\OperatorTok{/}\DecValTok{2}\NormalTok{,Q1.delta.thr),}\DataTypeTok{labels=}\KeywordTok{c}\NormalTok{(}\StringTok{"0 ppm"}\NormalTok{,}\KeywordTok{paste}\NormalTok{(}\KeywordTok{round}\NormalTok{(Q1.delta.thr}\OperatorTok{/}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{),}\StringTok{" ppm"}\NormalTok{,}\DataTypeTok{sep=}\StringTok{""}\NormalTok{),}\KeywordTok{paste}\NormalTok{(}\KeywordTok{round}\NormalTok{(Q1.delta.thr,}\DecValTok{1}\NormalTok{),}\StringTok{" ppm"}\NormalTok{,}\DataTypeTok{sep=}\StringTok{""}\NormalTok{)))}\OperatorTok{+}
\StringTok{      }\KeywordTok{ggtitle}\NormalTok{(}\DataTypeTok{label =} \KeywordTok{paste}\NormalTok{(}\StringTok{"Q1 mass error - SAMPLE:"}\NormalTok{,sample.name))}\OperatorTok{+}
\StringTok{      }\KeywordTok{geom_text}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\DataTypeTok{label=}\KeywordTok{round}\NormalTok{(Error, }\DataTypeTok{digits =} \DecValTok{2}\NormalTok{)),}\DataTypeTok{size =} \DecValTok{3}\NormalTok{)}\OperatorTok{+}
\StringTok{      }\KeywordTok{theme}\NormalTok{(}\DataTypeTok{panel.grid.major =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{panel.border =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{panel.background =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{axis.ticks =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{axis.text.x =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{7}\NormalTok{, }\DataTypeTok{vjust =} \FloatTok{0.5}\NormalTok{),}
            \DataTypeTok{axis.text.y =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{8}\NormalTok{),}
            \DataTypeTok{legend.title =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{legend.position =} \StringTok{"top"}\NormalTok{, }
            \DataTypeTok{legend.spacing.x =} \KeywordTok{unit}\NormalTok{(}\FloatTok{0.1}\NormalTok{, }\StringTok{'cm'}\NormalTok{),}
            \DataTypeTok{legend.text =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{7}\NormalTok{),}
            \DataTypeTok{axis.title.y =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{plot.title =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{10}\NormalTok{, }\DataTypeTok{face =} \StringTok{"bold"}\NormalTok{,}\DataTypeTok{hjust =} \DecValTok{0}\NormalTok{),}
            \DataTypeTok{axis.title.x =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size=}\DecValTok{7}\NormalTok{))}\OperatorTok{+}
\StringTok{      }\KeywordTok{geom_vline}\NormalTok{(}\DataTypeTok{xintercept =} \FloatTok{7.5}\NormalTok{, }\DataTypeTok{colour =} \StringTok{"lightskyblue4"}\NormalTok{, }\DataTypeTok{size =} \DecValTok{2}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Warning: Removed 1 rows containing missing values (geom_text).
\end{verbatim}

\includegraphics{MS1-HRMS-Extractor_files/figure-latex/unnamed-chunk-23-1.pdf}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#           Q2 error plots}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{\{}
\NormalTok{  holder.pos <-}\StringTok{ }\KeywordTok{subset}\NormalTok{(results.pos.reshape,}\DataTypeTok{select =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\OperatorTok{:}\DecValTok{3}\NormalTok{,}\DecValTok{6}\NormalTok{,}\DecValTok{13}\NormalTok{,}\DecValTok{20}\NormalTok{,}\DecValTok{27}\NormalTok{,}\DecValTok{34}\NormalTok{,}\DecValTok{41}\NormalTok{,}\DecValTok{48}\NormalTok{))}
\NormalTok{  heatmap.q2.pos <-}\StringTok{ }\KeywordTok{melt}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ holder.pos[}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{,}\DecValTok{3}\OperatorTok{:}\DecValTok{9}\NormalTok{)],}\DataTypeTok{measure.vars =} \KeywordTok{colnames}\NormalTok{(holder.pos[}\DecValTok{3}\OperatorTok{:}\DecValTok{9}\NormalTok{]),}\DataTypeTok{id.vars =} \KeywordTok{c}\NormalTok{(}\StringTok{"Class"}\NormalTok{,}\StringTok{"Compound"}\NormalTok{),}\DataTypeTok{variable.name =} \StringTok{"Species"}\NormalTok{)}
  \KeywordTok{levels}\NormalTok{(heatmap.q2.pos}\OperatorTok{$}\NormalTok{Species) <-}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"[M+H]+"}\NormalTok{,}\StringTok{"[M+NH4]+"}\NormalTok{,}\StringTok{"[M+Na]+"}\NormalTok{,}\StringTok{"[M+K]+"}\NormalTok{,}\StringTok{"[M+CH3OH+H]+"}\NormalTok{,}\StringTok{"[2M+H]+"}\NormalTok{,}\StringTok{"[M+2H]+"}\NormalTok{)}
  \KeywordTok{levels}\NormalTok{(heatmap.q2.pos}\OperatorTok{$}\NormalTok{Species) <-}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"1P"}\NormalTok{,}\StringTok{"2P"}\NormalTok{,}\StringTok{"3P"}\NormalTok{,}\StringTok{"4P"}\NormalTok{,}\StringTok{"5P"}\NormalTok{,}\StringTok{"6P"}\NormalTok{,}\StringTok{"7P"}\NormalTok{)}
\NormalTok{  heatmap.q2 <-}\StringTok{ }\NormalTok{heatmap.q2.pos}
  \KeywordTok{colnames}\NormalTok{(heatmap.q2)[}\DecValTok{4}\NormalTok{] <-}\StringTok{ "Error"}
\NormalTok{\}}
\KeywordTok{ggplot}\NormalTok{(heatmap.q2, }\KeywordTok{aes}\NormalTok{(Species, Compound))}\OperatorTok{+}
\StringTok{      }\KeywordTok{geom_tile}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\DataTypeTok{fill =}\NormalTok{ Error), }\DataTypeTok{colour =} \StringTok{"lightskyblue4"}\NormalTok{, }\DataTypeTok{size =} \FloatTok{0.1}\NormalTok{, }\DataTypeTok{stat =} \StringTok{"identity"}\NormalTok{, }\DataTypeTok{width =} \DecValTok{1}\NormalTok{, }\DataTypeTok{height =} \DecValTok{1}\NormalTok{)}\OperatorTok{+}
\StringTok{      }\KeywordTok{scale_fill_gradientn}\NormalTok{(}\DataTypeTok{limits =} \KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,Q2.delta.thr),}\DataTypeTok{colours=} \KeywordTok{c}\NormalTok{(}\StringTok{"olivedrab1"}\NormalTok{,}\StringTok{"darkorange"}\NormalTok{,}\StringTok{"indianred1"}\NormalTok{),}\DataTypeTok{na.value =} \StringTok{"grey"}\NormalTok{,}\DataTypeTok{breaks=}\KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,Q2.delta.thr}\OperatorTok{/}\DecValTok{2}\NormalTok{,Q2.delta.thr),}\DataTypeTok{labels=}\KeywordTok{c}\NormalTok{(}\StringTok{"0 ppm"}\NormalTok{,}\KeywordTok{paste}\NormalTok{(}\KeywordTok{round}\NormalTok{(Q2.delta.thr}\OperatorTok{/}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{),}\StringTok{" ppm"}\NormalTok{,}\DataTypeTok{sep=}\StringTok{""}\NormalTok{),}\KeywordTok{paste}\NormalTok{(}\KeywordTok{round}\NormalTok{(Q2.delta.thr,}\DecValTok{1}\NormalTok{),}\StringTok{" ppm"}\NormalTok{,}\DataTypeTok{sep=}\StringTok{""}\NormalTok{)))}\OperatorTok{+}
\StringTok{      }\KeywordTok{ggtitle}\NormalTok{(}\DataTypeTok{label =} \KeywordTok{paste}\NormalTok{(}\StringTok{"Q2 mass error - SAMPLE:"}\NormalTok{,sample.name))}\OperatorTok{+}
\StringTok{      }\KeywordTok{geom_text}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\DataTypeTok{label=}\KeywordTok{round}\NormalTok{(Error, }\DataTypeTok{digits =} \DecValTok{2}\NormalTok{)),}\DataTypeTok{size =} \DecValTok{3}\NormalTok{)}\OperatorTok{+}
\StringTok{      }\KeywordTok{theme}\NormalTok{(}\DataTypeTok{panel.grid.major =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{panel.border =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{panel.background =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{axis.ticks =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{axis.text.x =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{7}\NormalTok{, }\DataTypeTok{vjust =} \FloatTok{0.5}\NormalTok{),}
            \DataTypeTok{axis.text.y =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{8}\NormalTok{),}
            \DataTypeTok{legend.title =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{legend.position =} \StringTok{"top"}\NormalTok{, }
            \DataTypeTok{legend.spacing.x =} \KeywordTok{unit}\NormalTok{(}\FloatTok{0.1}\NormalTok{, }\StringTok{'cm'}\NormalTok{),}
            \DataTypeTok{legend.text =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{7}\NormalTok{),}
            \DataTypeTok{axis.title.y =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{plot.title =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{10}\NormalTok{, }\DataTypeTok{face =} \StringTok{"bold"}\NormalTok{,}\DataTypeTok{hjust =} \DecValTok{0}\NormalTok{),}
            \DataTypeTok{axis.title.x =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size=}\DecValTok{7}\NormalTok{))}\OperatorTok{+}
\StringTok{      }\KeywordTok{geom_vline}\NormalTok{(}\DataTypeTok{xintercept =} \FloatTok{7.5}\NormalTok{, }\DataTypeTok{colour =} \StringTok{"lightskyblue4"}\NormalTok{, }\DataTypeTok{size =} \DecValTok{2}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Warning: Removed 1 rows containing missing values (geom_text).
\end{verbatim}

\includegraphics{MS1-HRMS-Extractor_files/figure-latex/unnamed-chunk-25-1.pdf}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#           Q2/Q1 ratio error plots}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{\{}
\NormalTok{  holder.pos <-}\StringTok{ }\KeywordTok{subset}\NormalTok{(results.pos.reshape,}\DataTypeTok{select =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\OperatorTok{:}\DecValTok{3}\NormalTok{,}\DecValTok{7}\NormalTok{,}\DecValTok{14}\NormalTok{,}\DecValTok{21}\NormalTok{,}\DecValTok{28}\NormalTok{,}\DecValTok{35}\NormalTok{,}\DecValTok{42}\NormalTok{,}\DecValTok{49}\NormalTok{))}
\NormalTok{  heatmap.ratio.pos <-}\StringTok{ }\KeywordTok{melt}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ holder.pos[}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{,}\DecValTok{3}\OperatorTok{:}\DecValTok{9}\NormalTok{)],}\DataTypeTok{measure.vars =} \KeywordTok{colnames}\NormalTok{(holder.pos[}\DecValTok{3}\OperatorTok{:}\DecValTok{9}\NormalTok{]),}\DataTypeTok{id.vars =} \KeywordTok{c}\NormalTok{(}\StringTok{"Class"}\NormalTok{,}\StringTok{"Compound"}\NormalTok{),}\DataTypeTok{variable.name =} \StringTok{"Species"}\NormalTok{)}
  \KeywordTok{levels}\NormalTok{(heatmap.ratio.pos}\OperatorTok{$}\NormalTok{Species) <-}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"[M+H]+"}\NormalTok{,}\StringTok{"[M+NH4]+"}\NormalTok{,}\StringTok{"[M+Na]+"}\NormalTok{,}\StringTok{"[M+K]+"}\NormalTok{,}\StringTok{"[M+CH3OH+H]+"}\NormalTok{,}\StringTok{"[2M+H]+"}\NormalTok{,}\StringTok{"[M+2H]+"}\NormalTok{)}
  \KeywordTok{levels}\NormalTok{(heatmap.ratio.pos}\OperatorTok{$}\NormalTok{Species) <-}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"1P"}\NormalTok{,}\StringTok{"2P"}\NormalTok{,}\StringTok{"3P"}\NormalTok{,}\StringTok{"4P"}\NormalTok{,}\StringTok{"5P"}\NormalTok{,}\StringTok{"6P"}\NormalTok{,}\StringTok{"7P"}\NormalTok{)}
\NormalTok{  heatmap.ratio <-}\StringTok{ }\NormalTok{heatmap.ratio.pos}
  \KeywordTok{colnames}\NormalTok{(heatmap.ratio)[}\DecValTok{4}\NormalTok{] <-}\StringTok{ "Error"}
\NormalTok{  heatmap.ratio}\OperatorTok{$}\NormalTok{Error[heatmap.ratio}\OperatorTok{$}\NormalTok{Error }\OperatorTok{>}\StringTok{ }\DecValTok{100}\NormalTok{] <-}\StringTok{ }\OtherTok{NA}
\NormalTok{\}}
\KeywordTok{ggplot}\NormalTok{(heatmap.ratio, }\KeywordTok{aes}\NormalTok{(Species, Compound))}\OperatorTok{+}
\StringTok{      }\KeywordTok{geom_tile}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\DataTypeTok{fill =}\NormalTok{ Error), }\DataTypeTok{colour =} \StringTok{"lightskyblue4"}\NormalTok{, }\DataTypeTok{size =} \FloatTok{0.1}\NormalTok{, }\DataTypeTok{stat =} \StringTok{"identity"}\NormalTok{, }\DataTypeTok{width =} \DecValTok{1}\NormalTok{, }\DataTypeTok{height =} \DecValTok{1}\NormalTok{)}\OperatorTok{+}
\StringTok{      }\KeywordTok{scale_fill_gradientn}\NormalTok{(}\DataTypeTok{limits =} \KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{100}\NormalTok{),}\DataTypeTok{colours=} \KeywordTok{c}\NormalTok{(}\StringTok{"olivedrab1"}\NormalTok{,}\StringTok{"darkorange"}\NormalTok{,}\StringTok{"indianred1"}\NormalTok{),}\DataTypeTok{na.value =} \StringTok{"grey"}\NormalTok{,}\DataTypeTok{breaks=}\KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,Q2Q1.rato.error.thr,}\DecValTok{100}\NormalTok{),}\DataTypeTok{labels=}\KeywordTok{c}\NormalTok{(}\StringTok{"0%"}\NormalTok{,}\KeywordTok{paste}\NormalTok{(}\KeywordTok{round}\NormalTok{(Q2Q1.rato.error.thr,}\DecValTok{1}\NormalTok{),}\StringTok{" %"}\NormalTok{,}\DataTypeTok{sep=}\StringTok{""}\NormalTok{),}\StringTok{"100%"}\NormalTok{))}\OperatorTok{+}
\StringTok{      }\KeywordTok{ggtitle}\NormalTok{(}\DataTypeTok{label =} \KeywordTok{paste}\NormalTok{(}\StringTok{"Q2/Q1 Error - SAMPLE:"}\NormalTok{,sample.name))}\OperatorTok{+}
\StringTok{      }\KeywordTok{geom_text}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\DataTypeTok{label=}\KeywordTok{round}\NormalTok{(Error, }\DataTypeTok{digits =} \DecValTok{2}\NormalTok{)),}\DataTypeTok{size =} \DecValTok{3}\NormalTok{)}\OperatorTok{+}
\StringTok{      }\KeywordTok{theme}\NormalTok{(}\DataTypeTok{panel.grid.major =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{panel.border =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{panel.background =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{axis.ticks =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{axis.text.x =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{7}\NormalTok{, }\DataTypeTok{vjust =} \FloatTok{0.5}\NormalTok{),}
            \DataTypeTok{axis.text.y =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{8}\NormalTok{),}
            \DataTypeTok{legend.title =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{legend.position =} \StringTok{"top"}\NormalTok{, }
            \DataTypeTok{legend.spacing.x =} \KeywordTok{unit}\NormalTok{(}\FloatTok{0.1}\NormalTok{, }\StringTok{'cm'}\NormalTok{),}
            \DataTypeTok{legend.text =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{7}\NormalTok{),}
            \DataTypeTok{axis.title.y =} \KeywordTok{element_blank}\NormalTok{(),}
            \DataTypeTok{plot.title =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size =} \DecValTok{10}\NormalTok{, }\DataTypeTok{face =} \StringTok{"bold"}\NormalTok{,}\DataTypeTok{hjust =} \DecValTok{0}\NormalTok{),}
            \DataTypeTok{axis.title.x =} \KeywordTok{element_text}\NormalTok{(}\DataTypeTok{size=}\DecValTok{7}\NormalTok{))}\OperatorTok{+}
\StringTok{      }\KeywordTok{geom_vline}\NormalTok{(}\DataTypeTok{xintercept =} \FloatTok{7.5}\NormalTok{, }\DataTypeTok{colour =} \StringTok{"lightskyblue4"}\NormalTok{, }\DataTypeTok{size =} \DecValTok{2}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Warning: Removed 12 rows containing missing values (geom_text).
\end{verbatim}

\includegraphics{MS1-HRMS-Extractor_files/figure-latex/unnamed-chunk-27-1.pdf}


\end{document}
