R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

Step one: Load in tidyverse and simplify titles of raw files

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
A3 <- read.csv('A3_Pierce_Standard_0001_A3_26-07-17_13-30_0002.csv')
A4 <- read.csv('A4_2minTrypLC0c_0001_A4_26-07-17_13-36_0001.csv')

Step two: Cut your raw files to two columns, m/z and intensity

A3new <- A3[,1:2]
A4new <- A4[,c(1,2)]
names(A3new) <- c('m_z','int')
names(A4new) <- c('m_z','int')

Step three: Filter your raw files to contain 30-50 objects

A3filtered <- A3new[A3new$int>1000,]
A4filtered <- A4new[A4new$int>100,]
A3filtered$m_z <- round(A3filtered$m_z)
A4filtered$m_z <- round(A4filtered$m_z)

Step four: Use merge to keep perfect matches

matchDF <- merge(A3filtered,
                 A4filtered,by="m_z")

Step five: Tidy data

A3tidy <- cbind(sample='Standard',A3filtered)
A4tidy <- cbind(sample='Digest',A4filtered)
Matchtidy <- cbind(sample='Match',
                   matchDF[,c(1,3)])
names(Matchtidy) <- c('sample','m_z','int')
tidyDF <- rbind(A3tidy,
                A4tidy,
                Matchtidy)

Step six: Plot using ggplot and facet wrap

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)