- read in file
ms.data <- read.table("hyal1iso1f.txt",header=TRUE)
dim(ms.data) # OOPs, got only one column of data-- I need to specify separator=tab
ms.data <- read.table("hyal1iso1f.txt",header=TRUE, sep="\t")
dim(ms.data) # correct result of 42000+ rows and 2 columns
ms.data[1,] # see the first row
ms.data[1:10,] # see the first 10 rows
- plot the data
plot(ms.data,pch=".") # plot all of the data as tiny points
- use index vectors based on the logical AND (&) to grab the subset
of the data where the peak is. Then we will plot a SMOOTHED version.
peakregion <- ms.data[ms.data[,1]>45000 & ms.data[,1]<57000,]
plot(smooth.spline(peakregion), type="l", col="blue", xlab="m/z", ylab="intensity")
points(peakregion,pch=".") # good scientists always show the real data, not just the smoothed (fake!) results
- make a nice text label for the peak
intensity.max.y = max(peakregion[,2])
intensity.max.x = peakregion[peakregion[,2]==intensity.max.y,1]
peak.label = paste("max at ", format(intensity.max.x,nsmall=1))
text(intensity.max.x+3000, intensity.max.y-200, peak.label)
- finally, we use plot, points, text and get output in PostScript
postscript(file="ms.data.plot.ps",horizontal=FALSE, width=5,height=5)
plot(smooth.spline(peakregion,nknots=50),type="l", col="blue",xlab="m/z",ylab="intensity",main="Main peak region")
points(peakregion,pch=".")
text(intensity.max.x+3000, intensity.max.y-200, peak.label)
dev.off()
# "dev.off()" is needed because for R, PostScript is a live stream to an output
# device-- we have to shut off the tap now that we are done with it