[adegenet-commits] r174 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Sep 10 15:46:31 CEST 2008


Author: jombart
Date: 2008-09-10 15:46:31 +0200 (Wed, 10 Sep 2008)
New Revision: 174

Added:
   pkg/R/colorplot.R
Log:
Added a first draft of colorplot


Added: pkg/R/colorplot.R
===================================================================
--- pkg/R/colorplot.R	                        (rev 0)
+++ pkg/R/colorplot.R	2008-09-10 13:46:31 UTC (rev 174)
@@ -0,0 +1,34 @@
+colorplot <- function(xy, X, axes=1:ncol(X), add.plot=TRUE, ...){
+
+    ## some checks
+    if(any(is.na(xy))) stop("NAs exist in xy")
+    if(!is.numeric(xy)) stop("xy is not numeric")
+    if(nrow(xy) != nrow(X)) stop("xy and X have different row numbers")
+    X <- as.matrix(X[,axes,drop=FALSE])
+    if(any(is.na(X))) stop("NAs exist in X")
+    if(!is.numeric(X)) stop("X is not numeric")
+
+
+    ## function mapping x to [0,+inf[
+    f1 <- function(x){
+        x <- x + abs(min(x))
+        return(x)
+    }
+
+    ## apply f1 to X
+    X <- apply(X, 2, f1)
+
+    v1 <- X[,1]
+    if(ncol(X)==2) {v2 <- X[,2]} else {v2 <- 0}
+    if(ncol(X)==3) {v2 <- X[,3]} else {v3 <- 0}
+
+    ## find the colors
+    col <- rgb(v1, v2, v3, maxColorValue=max(X))
+
+    ## plot data
+    if(!add.plot) {
+        plot(xy, pch=20, col=col, ...)
+    } else {
+        points(xy, pch=20, col=col, ...)
+    }
+}



More information about the adegenet-commits mailing list