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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Mar 1 17:35:32 CET 2011


Author: jombart
Date: 2011-03-01 17:35:32 +0100 (Tue, 01 Mar 2011)
New Revision: 832

Added:
   pkg/R/glPlot.R
   pkg/man/glPlot.Rd
Log:
glplot files


Added: pkg/R/glPlot.R
===================================================================
--- pkg/R/glPlot.R	                        (rev 0)
+++ pkg/R/glPlot.R	2011-03-01 16:35:32 UTC (rev 832)
@@ -0,0 +1,40 @@
+
+###########
+## glPlot
+############
+glPlot <- function(x, col=NULL, legend=TRUE, posi="bottomleft", bg=rgb(1,1,1,.5),...) {
+
+    ## get plotted elements ##
+    X <- t(as.matrix(x))
+    X <- X[,ncol(X):1]
+    ylabpos <- pretty(1:nInd(x),5)
+    if(is.null(col)) {
+        myCol <- colorRampPalette(c("royalblue3", "firebrick1"))(max(X)+1)
+    } else {
+        myCol <- col
+    }
+
+    ## draw the plot ##
+    ## main plot
+    image(x=1:nLoc(x), y=1:nInd(x), z=X, xlab="SNP index", ylab="Individual index", yaxt="n",
+          col=myCol, ...)
+
+    ## add y axis
+    axis(side=2, at=nInd(x)-ylabpos, lab=ylabpos)
+
+    ## add legend
+    if(legend){
+        legend("bottomleft", fill=myCol, legend=0:max(X), horiz=TRUE, bg=bg, title="Number of 2nd allele")
+    }
+
+    return(invisible())
+} # end plot for glPlot
+
+
+
+
+## plot method
+setMethod("plot", signature(x="genlight", y="ANY"), function(x, y=NULL, col=NULL, legend=TRUE,
+                                          posi="bottomleft", bg=rgb(1,1,1,.5),...) {
+    glPlot(x, col=col, legend=legend, posi=posi, bg=bg, ...)
+})

Added: pkg/man/glPlot.Rd
===================================================================
--- pkg/man/glPlot.Rd	                        (rev 0)
+++ pkg/man/glPlot.Rd	2011-03-01 16:35:32 UTC (rev 832)
@@ -0,0 +1,63 @@
+\encoding{UTF-8}
+\name{glPlot}
+\alias{glPlot}
+\alias{plot.genlight}
+\alias{plot,genlight-method}
+\title{Plotting genlight objects}
+\description{
+  \linkS4class{genlight} object can be plotted using the function
+  \code{glPlot}, which is also used as the dedicated \code{plot}
+  method. These functions relie on \code{\link{image}} to represent SNPs
+  data. More specifically, colors are used to represent the number of
+  second allele for each locus and individual.
+}
+\usage{
+glPlot(x, col=NULL, legend=TRUE, posi="bottomleft", bg=rgb(1,1,1,.5),\dots)
+
+\S4method{plot}{genlight}(x, y=NULL, col=NULL, legend=TRUE, posi="bottomleft", bg=rgb(1,1,1,.5),\dots)
+
+}
+\arguments{
+  \item{x}{a \linkS4class{genlight} object.}
+  \item{col}{an optional color vector; the first value corresponds to 0
+    alleles, the last value corresponds to the ploidy level of the
+    data. Therefore, the vector should have a length of (\code{ploidy(x)+1}).}
+  \item{legend}{a logical indicating whether a legend should be added to
+    the plot.}
+  \item{posi}{a character string indicating where the legend should be
+    positioned. Can be any concatenation of "bottom"/"top" and "left"/"right".}
+  \item{bg}{a color used as a background for the legend; by default,
+    transparent white is used; this may not be supported on some
+    devices, and therefore background should be specified
+    (e.g. \code{bg="white"}).}
+  \item{\dots}{further arguments to be passed to \code{\link{image}}.}
+  \item{y}{ununsed argument, present for compatibility with the
+    \code{plot} generic.}
+}
+\seealso{
+  - \code{\link{genlight}}: class of object for storing massive binary
+  SNP data.
+  
+  - \code{\link{glSim}}: a simple simulator for \linkS4class{genlight}
+  objects.
+
+  - \code{\link{glPca}}: PCA for \linkS4class{genlight} objects.
+
+}
+\author{ Thibaut Jombart \email{t.jombart at imperial.ac.uk} }
+\examples{
+## simulate data
+x <- glSim(100, 1e3, n.snp.struc=100, ploid=2)
+
+## default plot
+glPlot(x)
+plot(x) # identical plot
+
+## disable legend
+plot(x, leg=FALSE)
+
+## use other colors
+plot(x, col=heat.colors(3), bg="white")
+
+}
+\keyword{multivariate}
\ No newline at end of file



More information about the adegenet-commits mailing list