Import data that was saved as ASCII in Shimadzu software

B2<-read.csv('B2.csv', header=F)
B3<-read.csv('B3.csv', header=F)
B2$V3<-'Standard Digest'
B3$V3<-'Experimental Digest'
B2<-B2[,1:3]
B3<-B3[,1:3]
ms_data<-rbind(B2,B3)
names(ms_data)<-c("mz",'intensity','Sample')

#Create a basic scatterplot plot with points

ggplot(ms_data, aes(x=mz, y=intensity))+
  geom_point(aes(color=Sample))+
  scale_color_manual(values=c('#ff00ff','#000099'))+
  scale_fill_manual(values=c('#ff00ff','#000099'))+
  xlab("m/z ratio")+ ylab("Millivolts") +
  theme(legend.position ='right')

#Create a basic column plot to compare samples

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

#Find peaks with identical mz

matchSpectra<-merge(B2,B3,by ="V1")
write.csv(matchSpectra,"matchSpectra.csv")