Skip to content

Commit

Permalink
fix bugs related to axes and limits
Browse files Browse the repository at this point in the history
New argument “axes”. Check xlim, ylim, glim, dlim are the correct
length.
  • Loading branch information
Aron Eklund committed Nov 25, 2015
1 parent ca3b3f8 commit 6a84d4f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
Expand Down
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
14 changes: 11 additions & 3 deletions R/beeswarm.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "",
...) {
Expand Down Expand Up @@ -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))
Expand All @@ -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)) {
Expand Down Expand Up @@ -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(...)
Expand Down
3 changes: 2 additions & 1 deletion man/beeswarm.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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). }
Expand Down

0 comments on commit 6a84d4f

Please sign in to comment.