diff lib.r @ 27:bed23aa27b4b draft

"planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 50478425b4773ebcb393c0e31f1e622b7406dcbb"
author workflow4metabolomics
date Thu, 24 Sep 2020 08:09:02 +0000
parents db6549f27ad1
children 018a9771de28
line wrap: on
line diff
--- a/lib.r	Tue May 12 16:39:28 2020 -0400
+++ b/lib.r	Thu Sep 24 08:09:02 2020 +0000
@@ -149,7 +149,11 @@
 
     par(mfrow = c(3, 1), mar = c(4, 4, 1, 0.5))
 
-    group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1")
+    if(length(unique(xdata$sample_group))<10){
+        group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1")
+    }else{
+        group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette="Dark 3")
+    }
     names(group_colors) <- unique(xdata$sample_group)
     col_per_samp <- as.character(xdata$sample_group)
     for(i in 1:length(group_colors)){col_per_samp[col_per_samp==(names(group_colors)[i])]<-group_colors[i]}
@@ -172,7 +176,11 @@
     pdf(file="raw_vs_adjusted_rt.pdf", width=16, height=12)
 
     # Color by group
-    group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1")
+    if(length(unique(xdata$sample_group))<10){
+        group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1")
+    }else{
+        group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette="Dark 3")
+    }
     if (length(group_colors) > 1) {
         names(group_colors) <- unique(xdata$sample_group)
         plotAdjustedRtime(xdata, col = group_colors[xdata$sample_group])
@@ -241,10 +249,14 @@
     pdf(pdfname, width=16, height=10)
 
     # Color by group
-    group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1")
+    if(length(unique(xdata$sample_group))<10){
+        group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1")
+    }else{
+        group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette="Dark 3")
+    }
     if (length(group_colors) > 1) {
         names(group_colors) <- unique(xdata$sample_group)
-        plot(chrom, col = group_colors[as.factor(chrom$sample_group)], main=main, peakType = "none")
+        plot(chrom, col = group_colors[chrom$sample_group], main=main, peakType = "none")
         legend("topright", legend=names(group_colors), col=group_colors, cex=0.8, lty=1)
     }