From 33c79f2dd4893abf5a03b98c403e9aa9ae16dab8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Todor=20Kondi=C4=87?= <todor.kondic@uni.lu>
Date: Mon, 24 Jun 2019 03:35:12 +0200
Subject: [PATCH] Update presc.plot

* R/mix.R(presc.plot): New argument.
  [pal] Colorbrewer palette.
---
 DESCRIPTION       |  3 ++-
 R/mix.R           | 11 +++++++----
 man/presc.plot.Rd |  4 +++-
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index 605680d..5e2ea25 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -23,4 +23,5 @@ Imports:
     RMassBank,
     parallel,
     yaml,
-    mzR
+    mzR,
+    RColorBrewer
diff --git a/R/mix.R b/R/mix.R
index dc14ce5..c1a2ee6 100644
--- a/R/mix.R
+++ b/R/mix.R
@@ -542,10 +542,11 @@ presc.p<-function(fn_data,fn_cmpd_l,mode,cl=NULL,ppm_lim_fine=10,EIC_limit=0.001
 ##' @title Plot the Output of Prescreen
 ##' @param wd Sequence of data dirs containing the prescreen subdir.
 ##' @param out The name of the output file.
+##' @param pal ColorBrewer palette name.
 ##' @return Nothing useful.
 ##' @author Todor Kondić
 ##' @export
-presc.plot <- function(wd,out="prescreen.pdf") {
+presc.plot <- function(wd,out="prescreen.pdf",pal="Accent") {
     dfdir <- file.path(wd,"prescreen")
     pdf(out)
     ## Get the basenames of eic files.
@@ -569,10 +570,12 @@ presc.plot <- function(wd,out="prescreen.pdf") {
         int_rng <- range(sapply(dfs,function(x) x$intensity)) 
         plot.window(rt_rng,int_rng)
         box()
-
+        cols <- RColorBrewer::brewer.pal(n=length(dfs),name=pal)
         ## Plot eic across the directory set.
-        for (df in dfs) {
-            lines(df$intensity ~ df$rt)
+        for (n in seq(length(dfs))) {
+            df <- dfs[[n]]
+            col <- cols[[n]]
+            lines(df$intensity ~ df$rt,col=col)
         }
 
         ## Find existing children and plot them across the directory
diff --git a/man/presc.plot.Rd b/man/presc.plot.Rd
index f8bfe68..4630dd7 100644
--- a/man/presc.plot.Rd
+++ b/man/presc.plot.Rd
@@ -4,12 +4,14 @@
 \alias{presc.plot}
 \title{Plot the Output of Prescreen}
 \usage{
-presc.plot(wd, out = "prescreen.pdf")
+presc.plot(wd, out = "prescreen.pdf", pal = "Accent")
 }
 \arguments{
 \item{wd}{Sequence of data dirs containing the prescreen subdir.}
 
 \item{out}{The name of the output file.}
+
+\item{pal}{ColorBrewer palette name.}
 }
 \value{
 Nothing useful.
-- 
GitLab