##Import data that was saved as ASCII in Shimadzu

C2<-read.csv('C2.csv', sep = ',', header = FALSE)
C3<-read.csv('C3.csv', sep = ',', header = FALSE)

##Clean up data by keeping columns of interest and merging into data set

C2$V3 <-'Standard Digest'
C3$V3 <- 'Experimental Digest'

C2 <-C2[,1:3]
C3 <-C3[,1:3]
ms_data<-rbind(C2,C3)
names(ms_data) <-c("MZ", 'Intensity', 'Sample')

##create scatter plot with points

library(ggplot2)
ggplot(ms_data, aes(x=MZ,y=Intensity))+
  geom_point(aes(colour=Sample))+
  scale_color_manual(values = c("#BA55D3","#FF7F50"))+
  theme_bw()+
  xlab("m/z ratio") + ylab("Millivolts")

##Create column plot to compare samples

ggplot(ms_data, aes(x=MZ,y=Intensity))+
  geom_col(aes(colour=Sample, fill=Sample))+
  scale_color_manual(values = c("#BA55D3","#FF7F50"))+
  scale_fill_manual(values = c("#BA55D3","#FF7F50"))+
  theme_bw()+
  xlab("m/z ratio") + ylab("Millivolts")

#find peaks with identical m/z ratios and export as a csv

matchspectra <-merge(C2,C3, by ="V1")
write.csv(matchspectra,"matchspectra.csv")