Separate Data Points by Jittering

DESCRIPTION:

Returns an object like the input but with values jittered by the addition of random noise.

USAGE:

jitter(x, factor=1, amount=0) 

REQUIRED ARGUMENTS:

x
numeric vector, matrix, or array.

OPTIONAL ARGUMENTS:

factor
number used to scale the range of added noise.
amount
if amount is positive then random uniforms between -amount and amount are added to the data. Otherwise factor is used to compute the range of the random uniforms based on the range of x.

VALUE:

object like x with random noise added to each term. The noise serves to separate points with identical values.

DETAILS:

Jittering is a convenient technique for separating points for plotting. The added noise is small compared with the range of the data, so the overall plot shape is not changed, yet each point appears as a unique dot.
If amount is not positive, the added noise is generated by runif from a range depending on the range of x and the scaling supplied by factor.

EXAMPLES:

  vec <- c(rep(1,2), rep(2,4), rep(3,4)) 
  jitter(vec) 
[1] 1.000522 1.027184 1.994750 2.038981 1.961557 
[6] 1.978223 2.973215 3.033884 2.962557 3.005580