Learn R Programming

beeswarm (version 0.1.1)

swarmx: Adjust 1-d data to separate coincident points

Description

Take a series of points lying in a horizontal or vertical line, and jitter them in the other dimension such that no points are overlapping.

Usage

swarmx(x, y, 
    xsize = xinch(0.08, warn.log = FALSE), 
    ysize = yinch(0.08, warn.log = FALSE),
    log = NULL, cex = par('cex'))
swarmy(x, y, 
    xsize = xinch(0.08, warn.log = FALSE), 
    ysize = yinch(0.08, warn.log = FALSE),
    log = NULL, cex = par('cex'))

Arguments

x, y
Coordinate vectors in any format supported by xy.coords.
xsize, ysize
Width and height of the plotting character in user coordinates.
log
Character string indicating which axes are logarithmic, as in plot.default, or NULL to figure it out automatically.
cex
Relative plotting character size.

Value

  • A data frame with columns x and y with the new coordinates.

Details

For swarmx, the input coordinates must lie in a vertical line. For swarmy, the input coordinates must lie in a horizontal line.

swarmx adjusts coordinates to the left or right; swarmy adjusts coordinates up or down.

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 xsize, ysize, and log will be appropriate.

See Also

beeswarm, jitter

Examples

Run this code
## Plot points in one dimension
index <- rep(0, 100)
values <- rnorm(100)
plot(index, values, xlim = c(-0.5, 2.5))
points(swarmx(index + 1, values), col = 2)
points(swarmx(index + 2, values, cex = 1.5), col = 3, cex = 1.5)

## Try the horizontal direction, with a log scale
plot(values, index, log = 'x', ylim = c(-1, 2))
points(swarmy(values, index + 1), col = 2)

Run the code above in your browser using DataLab