Skip to main content
Topic: Plot multiple EICs from the same sample (Read 6345 times) previous topic - next topic

Plot multiple EICs from the same sample

I see how to plot the extracted ion chromatograms for a single ion from multiple samples all in the same plot (getEIC and then plot that object), but how do you plot the extracted ion chromatograms for several ions from a single sample all in the same plot?

Laura

Re: Plot multiple EICs from the same sample

Reply #1
This is somehow similar to the CAMERA plotEICs function.
As far as I know you can't collapse all plots directly from the xcms plotEIC into one plot.
One solution could be to use the layout function, as Ralf suggested in another thread.
So multiple plots on one page. This should work with the normal plotEIC. Perhaps sleep > 0 not sure.

If you really want all EICs in one plot! (be aware of differences of retention time and intensity), try this snippet.
Is an adoption of the last example and the plot quality could perhaps be not optimal  ;)

Code: [Select]
#load libraries
library(xcms)
library(faahKO)

#normal pre-processing
xs.grp  <- group(faahko)
xs.ret  <- retcor(xs.grp)
xs.grp2  <- group(xs.ret)
xs.fill <- fillPeaks(xs.grp2)

#for example: peak 1 and 2 from sample 1
#also sampleidx="ko15" is okay
xeic.raw <- getEIC(xs.fill, rt = "raw", groupidx= c(1,2),sampleidx=1)

#get retention time ranges
rt <- xeic.raw@rtrange
rt.min <- min(rt[,"rtmin"])
rt.max <- max(rt[,"rtmax"])

#get mean mzranges (for legend)
mzrange <- apply(xeic.raw@mzrange,1,mean)
#get max. intensities
maxint <- sapply(xeic.raw@eic[[1]], function(x) max(x[,"intensity"]))

#generate plot
plot(0, 0, type = "n", xlim = c(rt.min,rt.max), ylim = c(0, max(maxint)),
    xaxs = "i", xlab = "Retention Time",
    ylab = "Intensity", main = paste("Extracted Ion Chromatograms for ",
                                      "nTime: From", round(rt.min,3), "to", round(rt.max,3)))

#make nice colors, change to number of peaks plotted
col <- c("red","blue")
for(i in seq(along=xeic.raw@eic[[1]])){
  points(xeic.raw@eic[[1]][[i]], type="l", col=col[i])
}
#make legend
legend("topright",col=col,legend=mzrange,lty=1)

Carsten