Add a small amount of noise to a numeric vector.
jitter(x, factor = 1, amount = NULL)
numeric vector to which jitter should be added.
numeric; if positive, used as amount (see below),
otherwise, if = 0 the default is factor * z/50.
factor * z/50
Default (NULL): factor * d/5 where d is about
the smallest difference between x values.
factor * d/5
jitter(x, …) returns a numeric of the same length as
x, but with an amount of noise added in order to break
The result, say r, is r <- x + runif(n, -a, a)
where n <- length(x) and a is the amount
argument (if specified).
r <- x + runif(n, -a, a)
n <- length(x)
Let z <- max(x) - min(x) (assuming the usual case).
The amount a to be added is either provided as positive
argument amount or otherwise computed from z, as
z <- max(x) - min(x)
If amount == 0, we set a <- factor * z/50 (same as S).
amount == 0
a <- factor * z/50
If amount is NULL (default), we set
a <- factor * d/5 where d is the smallest
difference between adjacent unique (apart from fuzz) x values.
a <- factor * d/5
Chambers, J. M., Cleveland, W. S., Kleiner, B. and Tukey, P.A. (1983)
Graphical Methods for Data Analysis. Wadsworth; figures 2.8,
Chambers, J. M. and Hastie, T. J. (1992)
Statistical Models in S.
Wadsworth & Brooks/Cole.
rug which you may want to combine with jitter.
round(jitter(c(rep(1, 3), rep(1.2, 4), rep(3, 3))), 3)
## These two 'fail' with S-plus 3.x:
Run the code above in your browser using DataCamp Workspace