[adegenet-commits] r882 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu May 26 18:40:08 CEST 2011


Author: jombart
Date: 2011-05-26 18:40:08 +0200 (Thu, 26 May 2011)
New Revision: 882

Modified:
   pkg/R/dapc.R
   pkg/man/dapc.Rd
Log:
Added a MStree to DAPC scatterplots.


Modified: pkg/R/dapc.R
===================================================================
--- pkg/R/dapc.R	2011-05-26 16:12:41 UTC (rev 881)
+++ pkg/R/dapc.R	2011-05-26 16:40:08 UTC (rev 882)
@@ -472,6 +472,7 @@
 ## scatter.dapc
 ##############
 scatter.dapc <- function(x, xax=1, yax=2, grp=NULL, col=rainbow(length(levels(x$grp))), pch=20, posi="bottomleft", bg="grey", ratio=0.3,
+                         mstree=FALSE, lwd=1, lty=1, segcol="black",
                          cstar = 1, cellipse = 1.5, axesell = TRUE, label = levels(x$grp), clabel = 1, xlim = NULL, ylim = NULL,
                          grid = TRUE, addaxes = TRUE, origin = c(0,0), include.origin = TRUE, sub = "", csub = 1, possub = "bottomleft",
                          posleg="topright", cleg=1, cgrid = 1, pixmap = NULL, contour = NULL, area = NULL, ...){
@@ -513,6 +514,18 @@
                 clabel = clabel, xlim = xlim, ylim = ylim, grid = grid, addaxes = addaxes, origin = origin, include.origin = include.origin,
                 sub = sub, csub = csub, possub = possub, cgrid = cgrid, pixmap = pixmap, contour = contour, area = area)
 
+        ## add minimum spanning tree if needed
+        if(mstree && require(ade4)){
+            meanposi <- apply(dapc1$tab,2, tapply, dapc1$grp, mean)
+            D <- dist(meanposi)^2
+            tre <- mstree(D)
+            x0 <- dapc1$grp.coord[tre[,1], axes[1]]
+            y0 <- dapc1$grp.coord[tre[,1], axes[2]]
+            x1 <- dapc1$grp.coord[tre[,2], axes[1]]
+            y1 <- dapc1$grp.coord[tre[,2], axes[2]]
+            segments(x0, y0, x1, y1, lwd=lwd, lty=lty, col=segcol)
+        }
+
         if(ratio>0.001) {
             add.scatter.eig(x$eig, ncol(x$loadings), axes[1], axes[2], posi=posi, ratio=ratio, csub=csub)
         }

Modified: pkg/man/dapc.Rd
===================================================================
--- pkg/man/dapc.Rd	2011-05-26 16:12:41 UTC (rev 881)
+++ pkg/man/dapc.Rd	2011-05-26 16:40:08 UTC (rev 882)
@@ -76,7 +76,8 @@
 
 \method{scatter}{dapc}(x, xax=1, yax=2, grp=NULL,
         col=rainbow(length(levels(x$grp))), pch=20, posi="bottomleft",
-        bg="grey", ratio=0.3, cstar = 1, cellipse = 1.5, axesell = TRUE,
+        bg="grey", ratio=0.3, mstree=TRUE, lwd=1, lty=1, segcol="black",
+        cstar = 1, cellipse = 1.5, axesell = TRUE,
         label = levels(x$grp), clabel = 1, xlim = NULL, ylim = NULL, grid
         = TRUE, addaxes = TRUE, origin = c(0,0), include.origin = TRUE,
         sub = "", csub = 1, possub = "bottomleft", posleg = "topright",
@@ -145,6 +146,13 @@
     of DAPC results. See \code{\link[ade4]{add.scatter}} documentation in the
     ade4 package for
     more details.}
+  \item{mstree}{a logical indicating whether a minimum spanning tree
+    based on the squared distances between groups should be
+    displayed (TRUE), or not (FALSE, default).}
+  \item{lwd,lty}{numeric values indicating the line width and type for
+    the minimum spanning tree, if \code{mstree=TRUE}.}
+  \item{segcol}{the color to be used to display the minimum spanning
+         tree, if \code{mstree=TRUE}.}
   \item{only.grp}{a \code{character} vector indicating which groups should be
     displayed. Values should match values of \code{x$grp}. If \code{NULL}, all
     results are displayed}
@@ -261,8 +269,8 @@
 pop(H3N2) <- factor(H3N2$other$epid)
 dapc1 <- dapc(H3N2, var.contrib=FALSE, scale=FALSE, n.pca=150, n.da=5)
 
-## remove internal segments and ellipses, different pch
-scatter(dapc1, cell=0, pch=18:23, cstar=0)
+## remove internal segments and ellipses, different pch, add MStree
+scatter(dapc1, cell=0, pch=18:23, cstar=0, mstree=TRUE, lwd=2, lty=2)
 
 ## only ellipse, custom labels
 scatter(dapc1, cell=2, pch="", cstar=0, posi="top",



More information about the adegenet-commits mailing list