Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

spreadout

Spread out a vector of numbers to a minimum interval


Description

Spread out a vector of numbers so that there is a minimum interval between any two numbers when in ascending or descending order.

Usage

spreadout(x,mindist)

Arguments

x

A numeric vector which may contain NAs.

mindist

The minimum interval between any two values when in ascending or descending order.

Details

spreadout starts at or near the middle of the vector and increases the intervals between the ordered values. NAs are preserved. spreadout first tries to spread groups of values with intervals less than mindist out neatly away from the mean of the group. If this doesn't entirely succeed, a second pass that forces values away from the middle is performed.

spreadout is currently used to avoid overplotting of axis tick labels where they may be close together.

Value

On success, the spread out values. If there are less than two valid values, the original vector is returned.

Author(s)

Jim Lemon

Examples

spreadout(c(1,3,3,3,3,5),0.2)
 spreadout(c(1,2.5,2.5,3.5,3.5,5),0.2)
 spreadout(c(5,2.5,2.5,NA,3.5,1,3.5,NA),0.2)
 # this will almost always invoke the brute force second pass
 spreadout(rnorm(10),0.5)

plotrix

Various Plotting Functions

v3.8-1
GPL (>= 2)
Authors
Jim Lemon, Ben Bolker, Sander Oom, Eduardo Klein, Barry Rowlingson, Hadley Wickham, Anupam Tyagi, Olivier Eterradossi, Gabor Grothendieck, Michael Toews, John Kane, Rolf Turner, Carl Witthoft, Julian Stander, Thomas Petzoldt, Remko Duursma, Elisa Biancotto, Ofir Levy, Christophe Dutang, Peter Solymos, Robby Engelmann, Michael Hecker, Felix Steinbeck, Hans Borchers, Henrik Singmann, Ted Toal, Derek Ogle, Darshan Baral, Ulrike Groemping, Bill Venables
Initial release
2021-01-21

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.