R Markdown

##Import data that was saved as ASCII in Shimadzu software

g2 <- read.csv('G2.csv', header = FALSE)
g3 <- read.csv('G3.csv', header = FALSE)
g2$V3 <- 'Pierce standard Digest'
g3$V3 <- 'Expierimental Digest'
g2 <-g2[,1:3]
g3 <-g3[,1:3]
ms_data <- rbind(g2,g3)
names(ms_data) <-c('mz','intensity','Sample')

#Create a basic scatter plot with points

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ 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
ggplot(ms_data, aes(x=mz,y=intensity)) + 
  geom_point(aes(color = Sample)) +
  scale_color_manual(values = c("#20AEAC","#df7d99")) +
  xlab("m/z ratio") + ylab("Millivolts") +
  theme(legend.position ="left")

#Create a column plot to compare spectra

library(tidyverse)
ggplot(ms_data, aes(x=mz,y=intensity)) + 
  geom_col(aes(color = Sample, fill=Sample)) +
  scale_color_manual(values=c("#20AEAC","#df7d99"))+
  scale_fill_manual(values=c("#20AEAC","#df7d99"))+
  xlab("m/z ratio") + ylab("Millivolts") +
  theme(legend.position ="right")

#Find peaks with identical m/z

matchSpectra <- merge(g2,g3, by="V1")
write.csv(matchSpectra, "matchSpectra.csv")