Import Data that was saved as ASCII in Shimasdzu software

d2 <- read.csv('D2.CSV', header = FALSE)
d3 <- read.csv('D3.CSV', header = FALSE)
d2$V3 <- 'Standart Dijest'
d3$V3 <- 'Experimental Digest'
d2<-d2[,1:3]
d3<-d3[,1:3]
ms_data <- rbind(d2,d3)
names(ms_data)<-c('mz','intensity','Sample')

#Createa 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(colour = Sample))+
  scale_color_manual(values = c("#df7d99","#7b96b8"))+
  xlab("m/z ratio") + ylab("Millivolts")+
  theme(legend.position = "left")

#Createa basic colum plotto compare spectra

ggplot(ms_data, aes(x=mz,y=intensity))+
  geom_col(aes(colour = Sample,fill=Sample))+
  scale_color_manual(values = c("#df7d99","#7b96b8"))+
  scale_fill_manual(values= c("#df7d99","#7b96b8"))+
  xlab("m/z ratio") + ylab("Millivolts")+
  theme(legend.position = "left")

#find peaks with identical m/z

matchSpectra <- merge(d2,d3, by="V1")
write.csv(matchSpectra,"matchSpectra.csv")