Skip to content

Commit

Permalink
Fix corral/side issue
Browse files Browse the repository at this point in the history
Fixed a bug in which specifying non-default values for both "corral"
and "side" arguments would result in unexpected results. (Issue #2)
  • Loading branch information
Aron Eklund committed Apr 25, 2016
1 parent db982c4 commit 863b806
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 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.2
Date: 2015-11-25
Version: 0.2.3
Date: 2016-04-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.3 (2016-04-25)

- Fixed a bug in which specifying non-default "corral" and "side" arguments would result in unexpected results. (Issue #2)


Changes in version 0.2.2 (2015-11-25)

- Check that glim, dlim, xlim, ylim have length 2, thus avoiding confusing errors.
Expand Down
15 changes: 10 additions & 5 deletions R/beeswarm.R
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,23 @@ beeswarm.default <- function(x,
stopifnot(length(corralWidth) == 1)
stopifnot(corralWidth > 0)
}
halfCorralWidth <- corralWidth / 2
corralLo <- (side - 1) * corralWidth / 2
corralHi <- (side + 1) * corralWidth / 2
if(corral == 'gutter') {
g.offset <- lapply(g.offset, function(zz) pmin(halfCorralWidth, pmax(-halfCorralWidth, zz)))
g.offset <- lapply(g.offset, function(zz) pmin(corralHi, pmax(corralLo, zz)))
}
if(corral == 'wrap') {
g.offset <- lapply(g.offset, function(zz) ((zz + halfCorralWidth) %% (halfCorralWidth * 2)) - halfCorralWidth)
if(side == -1) { ## special case with side=-1: reverse the corral to avoid artifacts at zero
g.offset <- lapply(g.offset, function(zz) corralHi - ((corralHi - zz) %% corralWidth))
} else {
g.offset <- lapply(g.offset, function(zz) ((zz - corralLo) %% corralWidth) + corralLo)
}
}
if(corral == 'random') {
g.offset <- lapply(g.offset, function(zz) ifelse(zz > halfCorralWidth | zz < -halfCorralWidth, runif(length(zz), -halfCorralWidth, halfCorralWidth), zz))
g.offset <- lapply(g.offset, function(zz) ifelse(zz > corralHi | zz < corralLo, yes = runif(length(zz), corralLo, corralHi), no = zz))
}
if(corral == 'omit') {
g.offset <- lapply(g.offset, function(zz) ifelse(zz > halfCorralWidth, NA, ifelse(zz < -halfCorralWidth, NA, zz)))
g.offset <- lapply(g.offset, function(zz) ifelse(zz > corralHi | zz < corralLo, yes = NA, no = zz))
}
}

Expand Down

0 comments on commit 863b806

Please sign in to comment.