[med-svn] [r-cran-beeswarm] 01/02: Imported Upstream version 0.2.0

Dylan Aïssi bob.dybian-guest at moszumanska.debian.org
Wed May 13 04:07:33 UTC 2015


This is an automated email from the git hooks/post-receive script.

bob.dybian-guest pushed a commit to branch master
in repository r-cran-beeswarm.

commit 83b192f7d3c208c5bf102334b49b88a1dd47d184
Author: Dylan Aïssi <bob.dybian at gmail.com>
Date:   Wed May 13 06:06:29 2015 +0200

    Imported Upstream version 0.2.0
---
 DESCRIPTION     |  11 +++--
 MD5             |  12 ++---
 NEWS            |  17 ++++++-
 R/beeswarm.R    | 143 +++++++++++++++++++++++++++++++++++---------------------
 R/bxplot.R      |   3 +-
 man/beeswarm.Rd |  25 +++++++++-
 man/swarmx.Rd   |  18 ++++++-
 7 files changed, 159 insertions(+), 70 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index fc14c55..05175db 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,13 +1,14 @@
 Package: beeswarm
-Version: 0.1.6
-Date: 2013-09-18
-Title: The bee swarm plot, an alternative to stripchart
+Version: 0.2.0
+Date: 2015-05-04
+Title: The Bee Swarm Plot, an Alternative to Stripchart
 Author: Aron Eklund
 Maintainer: Aron Eklund <eklund+beeswarm at cbs.dtu.dk>
+Depends: stats, graphics
 Description: The bee swarm plot is a one-dimensional scatter plot like "stripchart", but with closely-packed, non-overlapping points. 
 License: Artistic-2.0
 URL: http://www.cbs.dtu.dk/~eklund/beeswarm/
-Packaged: 2013-09-20 13:50:51 UTC; aron
 NeedsCompilation: no
+Packaged: 2015-05-04 12:54:32 UTC; aron
 Repository: CRAN
-Date/Publication: 2013-09-20 16:39:35
+Date/Publication: 2015-05-04 15:48:52
diff --git a/MD5 b/MD5
index ea0851d..0b5cb98 100644
--- a/MD5
+++ b/MD5
@@ -1,11 +1,11 @@
-4cef87738c855a220bd7e59bf77c8bf9 *DESCRIPTION
+a9fb6c11b9a5cc9d4316b590acee4927 *DESCRIPTION
 b641ad00a22a083cca208de1fb31b268 *NAMESPACE
-6b1b075c2e8e5abbef4133bfc7938cb7 *NEWS
-01e6fa4e1ec5d55b5c588df9a711a829 *R/beeswarm.R
-643471dc2a194e0696ced4f40cd29f35 *R/bxplot.R
+edc1989bd7d1d741e9c7e27b0d1d56ae *NEWS
+1c98d3ec63a0d15d8421d8295415888c *R/beeswarm.R
+99b47bff686cbb9afaf34e18a74ce49d *R/bxplot.R
 16cc12d2742742718c88949f18d5ac5d *R/zzz.R
 bcf102fab14afb8d779c8c4148685174 *data/breast.RData
-d6942ba25f56ac90174b92d2751056a6 *man/beeswarm.Rd
+25cf8f880ceab450935c22bc91bb5f74 *man/beeswarm.Rd
 1ee38a2972fa0874a81c807e36dd22a6 *man/breast.Rd
 d7097bb52220995656e837936b892d12 *man/bxplot.Rd
-7fc0307d8fc01021340dd59121c0acf3 *man/swarmx.Rd
+39895501e8f57e66d39377f43cf0eae7 *man/swarmx.Rd
diff --git a/NEWS b/NEWS
index 7369939..0c20b1b 100644
--- a/NEWS
+++ b/NEWS
@@ -1,10 +1,25 @@
 beeswarm NEWS
 
+Changes in version 0.2.0 (2015-05-04)
+
+- New arguments "side" and "priority" for beeswarm, swarmx, and swarmy. "side" allows swarms to grow on only one side rather than both sides. "priority" controls the order in which swarms are built, thus affecting the appearance of the plot. Thanks to Jon Lake and Brad Stiritz for suggestions.
+
+
+Changes in version 0.1.8 (2015-04-30)
+
+- Added "Depends: stats" to DESCRIPTION and removed "require(stats)" calls from code in order to achieve a clean package check
+
+
+Changes in version 0.1.7 (2014-08-05)
+
+- ".calculateSwarm" now performs the swarm point layout more efficiently
+
+
 Changes in version 0.1.6 (2013-09-18)
 
 - The argument "labels" now gets recycled. 
 - "labels = NULL" is now the same as missing "labels"; i.e. labels are inferred from data.
-- There is now a "width" argument to control the size of corrals, if corrals are used.
+- There is now a "corralWidth" argument to control the size of corrals, if corrals are used.
 
 
 Changes in version 0.1.5 (2012-05-07)
diff --git a/R/beeswarm.R b/R/beeswarm.R
index f6b2d47..894c314 100644
--- a/R/beeswarm.R
+++ b/R/beeswarm.R
@@ -17,7 +17,8 @@ beeswarm.default <- function(x,
     cex = 1, spacing = 1, breaks = NULL,
     labels, at = NULL, 
     corral = c("none", "gutter", "wrap", "random", "omit"),
-    corralWidth,
+    corralWidth, side = 0L, 
+    priority = c("ascending", "descending", "density", "random", "none"),
     pch = par("pch"), col = par("col"), bg = NA, 
     pwpch = NULL, pwcol = NULL, pwbg = NULL,
     do.plot = TRUE, add = FALSE, log = FALSE, 
@@ -25,15 +26,16 @@ beeswarm.default <- function(x,
     xlab = NULL, ylab = NULL, dlab = "", glab = "",
     ...) {
     
-  method = match.arg(method)
-  corral = match.arg(corral)
+  method <- match.arg(method)
+  corral <- match.arg(corral)
+  priority <- match.arg(priority)
   if(length(cex) > 1) {
     stop('the parameter "cex" must have length 1')
   }
+  stopifnot(side %in% -1:1)
   if(is.numeric(x)) {
     x <- list(x)
   }
-
   n.groups <- length(x)
 
   #### Resolve group labels
@@ -82,7 +84,7 @@ beeswarm.default <- function(x,
   if(is.null(glim)) {
     glim <- c(min(at) - 0.5, max(at) + 0.5)
   }
-  if(horizontal) { 
+  if(horizontal) {        ## plot is horizontal
     if(is.null(ylim)) 
       ylim <- glim
     if(is.null(xlim)) {
@@ -94,7 +96,7 @@ beeswarm.default <- function(x,
       xlab <- dlab
     if (is.null(ylab)) 
       ylab <- glab
-  } else {     ## vertical
+  } else {                ## plot is vertical
     if(is.null(xlim)) 
       xlim <- glim
     if(is.null(ylim)) {
@@ -166,18 +168,20 @@ beeswarm.default <- function(x,
     size.d <- yinch(0.08, warn.log = FALSE) * sizeMultiplier
   }
   
-## Calculate point positions g.pos, d.pos 
+  ##### Calculate point positions g.pos, d.pos 
   if(method == 'swarm') {
     if(horizontal) {
-      g.offset <- lapply(x, function(a) swarmy(x = a, y = rep(0, length(a)), cex = sizeMultiplier)$y)
+      g.offset <- lapply(x, function(a) swarmy(x = a, y = rep(0, length(a)), 
+          cex = sizeMultiplier, side = side, priority = priority)$y)
     } else {
-      g.offset <- lapply(x, function(a) swarmx(x = rep(0, length(a)), y = a, cex = sizeMultiplier)$x)
+      g.offset <- lapply(x, function(a) swarmx(x = rep(0, length(a)), y = a, 
+          cex = sizeMultiplier, side = side, priority = priority)$x)
     }
     d.pos <- x
-  } else {
-      if(method == 'hex') size.d <- size.d * sqrt(3) / 2
-    
-      if(log) {
+  } else {          ####   non-swarm methods
+    ##### first determine positions along the data axis
+      if(method == 'hex') size.d <- size.d * sqrt(3) / 2  
+      if(log) {              ## if data axis IS on a log scale
         if(is.null(breaks))
           breaks <- 10 ^ seq(log10(dlim[1]), log10(dlim[2]) + size.d, by = size.d)
         if(length(breaks) == 1 && is.na(breaks[1])) {
@@ -188,7 +192,7 @@ beeswarm.default <- function(x,
           d.index <- lapply(x, cut, breaks = breaks, labels = FALSE)
           d.pos <- lapply(d.index, function(a) mids[a])  
         }
-      } else {
+      } else {               ## if data axis is NOT on a log scale
         if(is.null(breaks))
           breaks <- seq(dlim[1], dlim[2] + size.d, by = size.d)
         if(length(breaks) == 1 && is.na(breaks[1])) {
@@ -200,26 +204,39 @@ beeswarm.default <- function(x,
           d.pos <- lapply(d.index, function(a) mids[a])  
         }
       }  
-    
+    ##### now determine positions along the group axis
       x.index <- lapply(d.index, function(v) {
-        if(length(na.omit(v)) == 0) return(v)
+        if(length(na.omit(v)) == 0) 
+          return(v)
         v.s <- lapply(split(v, v), seq_along)
-        if(method == 'center')
+        if(method %in% c('center', 'square') && side == -1)
+          v.s <- lapply(v.s, function(a) a - max(a))
+        else if(method %in% c('center', 'square') && side == 1)
+          v.s <- lapply(v.s, function(a) a - 1)
+        else if(method == 'center')
           v.s <- lapply(v.s, function(a) a - mean(a))
         else if(method == 'square')
           v.s <- lapply(v.s, function(a) a - floor(mean(a)))
         else if(method == 'hex') {
           odd.row <- (as.numeric(names(v.s)) %% 2) == 1
-          v.s[odd.row] <- lapply(v.s[odd.row], function(a) a - floor(mean(a)) - 0.25)
-          v.s[!odd.row] <- lapply(v.s[!odd.row], function(a) a - ceiling(mean(a)) + 0.25)
+          if(side == 0) {
+            v.s[ odd.row] <- lapply(v.s[ odd.row], function(a) a - floor(mean(a)) - 0.25)
+            v.s[!odd.row] <- lapply(v.s[!odd.row], function(a) a - ceiling(mean(a)) + 0.25)
+          } else if(side == -1) {
+            v.s[ odd.row] <- lapply(v.s[ odd.row], function(a) a - max(a))
+            v.s[!odd.row] <- lapply(v.s[!odd.row], function(a) a - max(a) - 0.5)
+          } else if(side ==  1) {
+            v.s[ odd.row] <- lapply(v.s[ odd.row], function(a) a - 1)
+            v.s[!odd.row] <- lapply(v.s[!odd.row], function(a) a - 0.5)
+          }
         }
         unsplit(v.s, v)
       }) 
       
       g.offset <- lapply(1:n.groups, function(i) x.index[[i]] * size.g)
-  }
+  }                   ###### end of non-swarm methods
 
-  ## now check for runaway points (if "corral" has been set)
+  ##### now check for runaway points (if "corral" has been set)
   if(corral != 'none') {
     if(missing(corralWidth)) {
       if(n.groups > 1) {
@@ -254,14 +271,14 @@ beeswarm.default <- function(x,
                     stringsAsFactors = FALSE)
 
   if(do.plot) {
-    if(horizontal) { 
+    if(horizontal) {     ## plot is horizontal
       points(out$y, out$x, pch = out$pch, col = out$col, bg = out$bg, cex = cex)  
       if(!add) {
         axis(1, ...)
         axis(2, at = at, labels = labels, tick = FALSE, ...)
         box(...)
       }
-    } else {
+    } else {             ## plot is vertical
       points(out$x, out$y, pch = out$pch, col = out$col, bg = out$bg, cex = cex)  
       if(!add) {
         axis(2, ...)
@@ -273,6 +290,7 @@ beeswarm.default <- function(x,
   invisible(out)
 }
 
+   
   
 beeswarm.formula <- function (formula, data = NULL, subset, na.action = NULL, 
     pwpch = NULL, pwcol = NULL, pwbg = NULL, dlab, glab, ...) 
@@ -286,7 +304,6 @@ beeswarm.formula <- function (formula, data = NULL, subset, na.action = NULL,
     m$dlab <- NULL
     m$glab <- NULL
     m$na.action <- na.action
-    require(stats, quietly = TRUE)
     m[[1]] <- as.name("model.frame")
     mf <- eval(m, parent.frame())
     response <- attr(attr(mf, "terms"), "response")
@@ -305,44 +322,62 @@ beeswarm.formula <- function (formula, data = NULL, subset, na.action = NULL,
 }
 
 
-## hidden function  
-.calculateSwarm <- function(x, dsize, gsize) {
+#### hidden function to do swarm layout
+.calculateSwarm <- function(x, dsize, gsize, side = 0L, priority = "ascending") {
   if(length(x) == 0) return(numeric(0))
-  out <- data.frame(x = x / dsize, y = 0, i = seq(along = x))
-  out <- out[order(out$x), ]
+  stopifnot(side %in% -1:1)
+  out <- data.frame(x = x / dsize, y = 0, index = seq(along = x))
+  
+  #### Determine the order in which points will be placed
+  if(     priority == "ascending" ) { out <- out[order( out$x), ] } ## default "smile"
+  else if(priority == "descending") { out <- out[order(-out$x), ] } ## frown
+  else if(priority == "none") {  } ## do not reorder
+  else if(priority == "density") {
+  	dens.x <- density(out$x, na.rm = TRUE)  ## compute kernel density estimate
+  	dens.interp <- approx(dens.x$x, dens.x$y, xout = out$x, rule = 2)  ## interpolated density
+  	out <- out[order(-dens.interp$y), ]  ## arrange outward from densest areas
+  }
+  else if(priority == "random") {
+	out <- out[sample(nrow(out)), ]
+  }
+  #### place the points
   if(nrow(out) > 1) {
-    for (i in 2:nrow(out)) {
-      xi <- out$x[i]
-      yi <- out$y[i]
-      pre <- out[1:(i - 1), ] # previous points
-      wh <- xi - pre$x < 1  # which ones are potentially overlapping
-      wh[is.na(wh)] <- FALSE  # missing values are not potentially overlapping
-      if(any(wh)) {
-        pre <- pre[wh, ]
-        pre <- pre[order(abs(pre$y)), ]
-        poty.off <- sqrt(1 - ((xi - pre$x) ^ 2)) # potential y offset
-        poty <- c(0, pre$y + poty.off, pre$y - poty.off) # potential y values
-        poty.bad <- sapply(poty, function(y) { # check for overlaps
-          any(((xi - pre$x) ^ 2 + (y - pre$y) ^ 2) < 0.999)
+    for (ii in 2:nrow(out)) {          ## we will place one point at a time
+      xi <- out$x[ii]
+       ## identify previously-placed points with potential to overlap the current point
+      isPotOverlap <- (abs(xi - out$x) < 1) & (1:nrow(out) < ii)
+      isPotOverlap[is.na(isPotOverlap)] <- FALSE
+      if(any(isPotOverlap)) {
+        pre.x <- out[isPotOverlap, 'x']
+        pre.y <- out[isPotOverlap, 'y']
+        poty.off <- sqrt(1 - ((xi - pre.x) ^ 2))         ## potential y offsets
+        poty <- switch(side + 2, 
+          c(0, pre.y - poty.off),
+          c(0, pre.y + poty.off, pre.y - poty.off),
+          c(0, pre.y + poty.off)
+        )
+        poty.bad <- sapply(poty, function(y) {           ## check for overlaps
+          any(((xi - pre.x) ^ 2 + (y - pre.y) ^ 2) < 0.999)
         })
         poty[poty.bad] <- Inf
-        out$y[i] <- poty[which.min(abs(poty))]
+        out$y[ii] <- poty[which.min(abs(poty))]
       } else {
-        out$y[i] <- 0
+        out$y[ii] <- 0
       }
     }
   }
-  out <- out[order(out$i), ]
-  out[is.na(out$x), 'y'] <- NA  # missing x values should have missing y values
-  out$y * gsize
+  out[is.na(out$x), 'y'] <- NA        ## missing x values should have missing y values
+  out$y[order(out$index)] * gsize
 }
 
 
-# jitter points horizontally
+### jitter points horizontally
 swarmx <- function(x, y, 
     xsize = xinch(0.08, warn.log = FALSE), 
     ysize = yinch(0.08, warn.log = FALSE),
-    log = NULL, cex = par("cex")) { 
+    log = NULL, cex = par("cex"), side = 0L, 
+    priority = c("ascending", "descending", "density", "random", "none")) { 
+  priority <- match.arg(priority)
   if(is.null(log)) 
     log <- paste(ifelse(par('xlog'), 'x', ''), ifelse(par('ylog'), 'y', ''), sep = '')
   xlog <- 'x' %in% strsplit(log, NULL)[[1L]]
@@ -351,17 +386,20 @@ swarmx <- function(x, y,
   stopifnot((length(unique(xy$x)) <= 1))
   if(xlog) xy$x <- log10(xy$x)
   if(ylog) xy$y <- log10(xy$y)
-  x.new <- xy$x + .calculateSwarm(xy$y, dsize = ysize * cex, gsize = xsize * cex)
+  x.new <- xy$x + .calculateSwarm(xy$y, dsize = ysize * cex, gsize = xsize * cex, 
+    side = side, priority = priority)
   out <- data.frame(x = x.new, y = y)
   if(xlog) out$x <- 10 ^ out$x
   out
 }
 
-# jitter points vertically
+### jitter points vertically
 swarmy <- function(x, y, 
     xsize = xinch(0.08, warn.log = FALSE), 
     ysize = yinch(0.08, warn.log = FALSE),
-    log = NULL, cex = par("cex")) { 
+    log = NULL, cex = par("cex"), side = 0L, 
+    priority = c("ascending", "descending", "density", "random", "none")) { 
+  priority <- match.arg(priority)
   if(is.null(log)) 
     log <- paste(ifelse(par('xlog'), 'x', ''), ifelse(par('ylog'), 'y', ''), sep = '')
   xlog <- 'x' %in% strsplit(log, NULL)[[1L]]
@@ -370,7 +408,8 @@ swarmy <- function(x, y,
   stopifnot((length(unique(xy$y)) <= 1))
   if(xlog) xy$x <- log10(xy$x)
   if(ylog) xy$y <- log10(xy$y)
-  y.new <- xy$y + .calculateSwarm(xy$x, dsize = xsize * cex, gsize = ysize * cex)
+  y.new <- xy$y + .calculateSwarm(xy$x, dsize = xsize * cex, gsize = ysize * cex, 
+    side = side, priority = priority)
   out <- data.frame(x = x, y = y.new)
   if(ylog) out$y <- 10 ^ out$y
   out
diff --git a/R/bxplot.R b/R/bxplot.R
index 2e9c453..4cb067f 100644
--- a/R/bxplot.R
+++ b/R/bxplot.R
@@ -19,7 +19,7 @@ bxplot.default <- function(x, probs = c(0.25, 0.5, 0.75),
   }
   n <- length(x)
   n.probs <- length(probs)
-  if(is.null(lwd)) { 
+  if(is.null(lwd)) {  ## default is a thick line at the median
     lwd <- rep(par('lwd'), length.out = n.probs)
     if(0.5 %in% probs) lwd[probs == 0.5] <- par('lwd') * 3
   }
@@ -53,7 +53,6 @@ bxplot.formula <- function (formula, data = NULL, ..., subset, na.action = NULL)
         m$data <- as.data.frame(data)
     m$... <- NULL
     m$na.action <- na.action
-    require(stats, quietly = TRUE)
     m[[1L]] <- as.name("model.frame")
     mf <- eval(m, parent.frame())
     response <- attr(attr(mf, "terms"), "response")
diff --git a/man/beeswarm.Rd b/man/beeswarm.Rd
index 31047f7..9c9040f 100644
--- a/man/beeswarm.Rd
+++ b/man/beeswarm.Rd
@@ -21,7 +21,8 @@ beeswarm(x, \dots)
     cex = 1, spacing = 1, breaks = NULL,
     labels, at = NULL, 
     corral = c("none", "gutter", "wrap", "random", "omit"),
-    corralWidth,
+    corralWidth, side = 0L, 
+    priority = c("ascending", "descending", "density", "random", "none"),
     pch = par("pch"), col = par("col"), bg = NA, 
     pwpch = NULL, pwcol = NULL, pwbg = NULL,
     do.plot = TRUE, add = FALSE, log = FALSE,
@@ -51,7 +52,9 @@ beeswarm(x, \dots)
   \item{at}{ Numeric vector giving the locations where the swarms should be drawn; defaults to \code{1:n} where \var{n} is the number of groups. }
   \item{corral}{ Method to adjust points that would be placed outside their own group region (see Details). }
   \item{corralWidth}{ Width of the "corral" in user coordinates. If missing, a sensible value will be chosen. }
-  \item{pch, col, bg}{ Plotting characters and colors, specified by group. Recycled if necessary. (see Details). }
+    \item{side}{ Direction to perform jittering: 0: both directions; 1: to the right or upwards; -1: to the left or downwards.}
+  \item{priority}{ Order used to perform point layout when method is \code{"swarm"}; ignored otherwise (see Details).}
+  \item{pch, col, bg}{ Plotting characters and colors, specified by group. Recycled if necessary (see Details). }
   \item{pwpch, pwcol, pwbg}{ \dQuote{Point-wise} plotting characters and colors, specified for each data point (see Details). }
   \item{do.plot}{ Draw a plot? }
   \item{add}{ Add to an existing plot? }
@@ -84,6 +87,9 @@ Alternatively, the \dQuote{point-wise} characteristics of each individual data p
 This function is intended to be mostly compatible with calls to \code{\link{stripchart}} or \code{\link{boxplot}}.  Thus, code that works with these functions should work with \code{beeswarm} with minimal modification.
 
 By default, swarms from different groups are not prevented from overlapping. Thus, large data sets, or data sets with uneven distributions, may produce somewhat unpleasing beeswarms. If this is a problem, consider reducing \code{cex}. Another approach is to control runaway points (those that would be plotted outside a region allotted to each group) with the \code{corral} argument: The default, \code{"none"}, does not control runaway points. \code{"gutter"} collects runaway points along t [...]
+
+When using the \code{"swarm"} method, \code{priority} controls the order in which the points are placed; this generally has a noticeable effect on the resulting appearance. \code{"ascending"} gives the "traditional" beeswarm plot in which the points are placed in an ascending order. \code{"descending"} is the opposite. \code{"density"} prioritizes points with higher local density. \code{"random"} places points in a random order. \code{"none"} places points in the order provided.
+
 }
 
 \value{ A data frame with plotting information, invisibly. }
@@ -142,6 +148,21 @@ By default, swarms from different groups are not prevented from overlapping. Thu
     main = 'corral = "random"')
   beeswarm(distributions, col = 2:4, corral = "omit", 
     main = 'corral = "omit"')  
+ 
+  ## Demonstrate 'side' and 'priority'
+  par(mfrow = c(2,3))
+  beeswarm(distributions, col = 2:4, 
+    main = 'Default')
+  beeswarm(distributions, col = 2:4, side = -1, 
+    main = 'side = -1')
+  beeswarm(distributions, col = 2:4, side = 1, 
+    main = 'side = 1')
+  beeswarm(distributions, col = 2:4, priority = "descending", 
+    main = 'priority = "descending"')
+  beeswarm(distributions, col = 2:4, priority = "random", 
+    main = 'priority = "random"')  
+  beeswarm(distributions, col = 2:4, priority = "density", 
+    main = 'priority = "density"')  
 }
 
 \keyword{ hplot }
diff --git a/man/swarmx.Rd b/man/swarmx.Rd
index f4c5aa4..bea7621 100644
--- a/man/swarmx.Rd
+++ b/man/swarmx.Rd
@@ -7,23 +7,29 @@
 swarmx(x, y, 
     xsize = xinch(0.08, warn.log = FALSE), 
     ysize = yinch(0.08, warn.log = FALSE),
-    log = NULL, cex = par("cex"))
+    log = NULL, cex = par("cex"), side = 0L, 
+    priority = c("ascending", "descending", "density", "random", "none"))
 swarmy(x, y, 
     xsize = xinch(0.08, warn.log = FALSE), 
     ysize = yinch(0.08, warn.log = FALSE),
-    log = NULL, cex = par("cex"))
+    log = NULL, cex = par("cex"), side = 0L, 
+    priority = c("ascending", "descending", "density", "random", "none"))
 }
 \arguments{
   \item{x, y}{ Coordinate vectors in any format supported by \code{\link{xy.coords}}. }
   \item{xsize, ysize}{ Width and height of the plotting character in user coordinates. }
   \item{log}{ Character string indicating which axes are logarithmic, as in \code{\link{plot.default}}, or \code{NULL} to figure it out automatically.}
   \item{cex}{ Relative plotting character size.}
+  \item{side}{ Direction to perform jittering: 0: both directions; 1: to the right or upwards; -1: to the left or downwards.}
+  \item{priority}{ Method used to perform point layout (see below).}
 }
 \details{ 
 For \code{swarmx}, the input coordinates must lie in a vertical line.  For \code{swarmy}, the input coordinates must lie in a horizontal line.
 
 \code{swarmx} adjusts coordinates to the left or right; \code{swarmy} adjusts coordinates up or down.
 
+\code{priority} controls the order in which the points are placed; this has generally has a noticeable effect on the resulting appearance. \code{"ascending"} gives the "traditional" beeswarm plot in which the points are placed in an ascending order. \code{"descending"} is the opposite. \code{"density"} prioritizes points with higher local density. \code{"random"} places points in a random order. \code{"none"} places points in the order provided.
+
 Usually it makes sense to call this function after a plotting device has already been set up (e.g. when adding points to an existing plot), so that the default values for \code{xsize}, \code{ysize}, and \code{log} will be appropriate.
 }
 \value{ A data frame with columns \code{x} and \code{y} with the new coordinates. }
@@ -41,5 +47,13 @@ points(swarmx(index + 2, values, cex = 1.5), col = 3, cex = 1.5)
 plot(values, index, log = "x", ylim = c(-1, 2))
 points(swarmy(values, index + 1), col = 2)
 
+## Newer examples using "side" and "priority"
+plot(c(-0.5, 3.5), range(values), type = 'n')
+points(swarmx(index + 0, values), col = 1)
+points(swarmx(index + 0.9, values, side = -1), col = 2)
+points(swarmx(index + 1.1, values, side =  1, priority = "descending"), col = 3)
+points(swarmx(index + 2  , values, priority = 'density'), col = 4)
+points(swarmx(index + 3  , values, priority = 'random'), col = 5)
+
 }
 \keyword{ dplot }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/r-cran-beeswarm.git



More information about the debian-med-commit mailing list