From 6a84d4f31b41b92ad3cdae73cb1318ac3622b8e4 Mon Sep 17 00:00:00 2001 From: Aron Eklund Date: Wed, 25 Nov 2015 14:30:31 +0100 Subject: [PATCH] fix bugs related to axes and limits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New argument “axes”. Check xlim, ylim, glim, dlim are the correct length. --- DESCRIPTION | 4 ++-- NEWS | 6 ++++++ R/beeswarm.R | 14 +++++++++++--- man/beeswarm.Rd | 3 ++- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6fd856b..ebfc448 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: beeswarm -Version: 0.2.1 -Date: 2015-08-26 +Version: 0.2.2 +Date: 2015-11-25 Title: The Bee Swarm Plot, an Alternative to Stripchart Author: Aron Eklund Maintainer: Aron Eklund diff --git a/NEWS b/NEWS index c822ca2..4ab8e64 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,11 @@ beeswarm NEWS +Changes in version 0.2.2 (2015-11-25) + +- Check that glim, dlim, xlim, ylim have length 2, thus avoiding confusing errors. +- New argument "axes" (previously, trying to specify "axes" in ... would cause an error). + + Changes in version 0.2.1 (2015-08-26) - Corrected NAMESPACE and DESCRIPTION to properly indicate Imports and to remove unnecessary Depends. diff --git a/R/beeswarm.R b/R/beeswarm.R index 894c314..b68c711 100644 --- a/R/beeswarm.R +++ b/R/beeswarm.R @@ -21,7 +21,7 @@ beeswarm.default <- function(x, 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, + do.plot = TRUE, add = FALSE, axes = TRUE, log = FALSE, xlim = NULL, ylim = NULL, dlim = NULL, glim = NULL, xlab = NULL, ylab = NULL, dlab = "", glab = "", ...) { @@ -80,9 +80,13 @@ beeswarm.default <- function(x, } else { dlim <- extendrange(x.val, f = 0.01) } + } else if (length(dlim) != 2) { + stop ("'dlim' must have length 2") } if(is.null(glim)) { glim <- c(min(at) - 0.5, max(at) + 0.5) + } else if (length(glim) != 2) { + stop ("'glim' must have length 2") } if(horizontal) { ## plot is horizontal if(is.null(ylim)) @@ -109,6 +113,10 @@ beeswarm.default <- function(x, if (is.null(xlab)) xlab <- glab } + if(length(xlim) != 2) + stop ("'xlim' must have length 2") + if(length(ylim) != 2) + stop ("'ylim' must have length 2") #### Resolve plotting characters and colors if(is.null(pwpch)) { @@ -273,14 +281,14 @@ beeswarm.default <- function(x, if(do.plot) { if(horizontal) { ## plot is horizontal points(out$y, out$x, pch = out$pch, col = out$col, bg = out$bg, cex = cex) - if(!add) { + if(axes & !add) { axis(1, ...) axis(2, at = at, labels = labels, tick = FALSE, ...) box(...) } } else { ## plot is vertical points(out$x, out$y, pch = out$pch, col = out$col, bg = out$bg, cex = cex) - if(!add) { + if(axes & !add) { axis(2, ...) axis(1, at = at, labels = labels, tick = FALSE, ...) box(...) diff --git a/man/beeswarm.Rd b/man/beeswarm.Rd index 9c9040f..7f4f4dd 100644 --- a/man/beeswarm.Rd +++ b/man/beeswarm.Rd @@ -25,7 +25,7 @@ beeswarm(x, \dots) 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, + do.plot = TRUE, add = FALSE, axes = TRUE, log = FALSE, xlim = NULL, ylim = NULL, dlim = NULL, glim = NULL, xlab = NULL, ylab = NULL, dlab = "", glab = "", \dots) @@ -58,6 +58,7 @@ beeswarm(x, \dots) \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? } + \item{axes}{ Draw axes and box? } \item{log}{ Use a logarithmic scale on the data axis? } \item{xlim, ylim}{ Limits of the plot. } \item{dlim, glim}{ An alternative way to specify limits (see Details). }