Call in required packages

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.3     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.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
library(dplyr)
library(ggplot2)

Import sample and standard data

library(readr)
PierceStandard <- read_csv("C:/Users/kxbst/Downloads/PierceStandard.csv")
## Rows: 924 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (7): Mass (Da), Intensity (mV), Intensity (%), Area (mV), Area (%), Reso...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
A4Sample <- read_csv("C:/Users/kxbst/Downloads/A4Sample.csv")
## Rows: 1249 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (7): Mass (Da), Intensity (mV), Intensity (%), Area (mV), Area (%), Reso...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Slice both dataframes to include only mass and intensity

PierceStandard_Slice <- PierceStandard[, 1:2]
A4Sample_Slice <- A4Sample[, 1:2]

Rename column headers for simplification

names(PierceStandard_Slice) <- c('m_z','int')
names(A4Sample_Slice) <- c('m_z','int')

Test filter the intensity column to minimize noise

Filtered_PierceStandard_Slice <- PierceStandard_Slice %>% filter(`int` > 100)
Filtered_A4Sample_Slice <- A4Sample_Slice %>% filter(`int` > 100)

Further filter on the intensity column to decrease spectra

Filtered_PierceStandard_Slice <- Filtered_PierceStandard_Slice %>% filter(`int` > 1000)
Filtered_A4Sample_Slice <- Filtered_A4Sample_Slice %>% filter(`int` > 100)

Round data from both data frames and merge matches

Filtered_PierceStandard_Slice$m_z <- round(Filtered_PierceStandard_Slice$m_z)
Filtered_A4Sample_Slice$m_z <- round(Filtered_A4Sample_Slice$m_z)
matchDF <- merge(Filtered_PierceStandard_Slice, Filtered_A4Sample_Slice, by="m_z")

Tidy all data

PierceTidy <- cbind(sample='Standard',Filtered_PierceStandard_Slice)
A4Tidy <- cbind(sample='A4',Filtered_A4Sample_Slice)
MatchTidy <- cbind(sample='Match',
                   matchDF[,c(1,3)])
names(MatchTidy) <- c('sample','m_z','int')
TidyDF <- rbind(PierceTidy, A4Tidy, MatchTidy)

Plot merged data

ggplot(TidyDF, aes(x = m_z,y=int))+
  geom_col(aes(colour = sample ,fill=sample))+
  xlab("m/z ratio") + ylab("Millivolts")+
  facet_wrap(~sample,nrow=3)