Skip to contents

This function expands a range by adding noise to the left of the minimum values and to the right of the maximum values.

Usage

jitter_range(data, factor = 1, amount = NULL)

Arguments

data

A dataframe with columns min and max.

factor

numeric.

amount

numeric; if positive, used as amount (see below), otherwise, if = 0 the default is factor * z/50.

Default (NULL): factor * d/5 where d is about the smallest difference between x values.

Value

The input dataframe with the additional columns min_jitter and max_jitter.

See also

Examples

library(tibble)
set.seed(123)

data <- tibble(min = -2:2, max = -1:3)

data |> jitter_range(amount = 0.1)
#> # A tibble: 5 × 4
#>     min   max min_jitter max_jitter
#>   <int> <int>      <dbl>      <dbl>
#> 1    -2    -1    -2.18     -0.920  
#> 2    -1     0    -1.01      0.00933
#> 3     0     1    -0.0182    1.09   
#> 4     1     2     0.990     2.07   
#> 5     2     3     1.98      3.27   

data |> jitter_range(amount = 2)
#> # A tibble: 5 × 4
#>     min   max min_jitter max_jitter
#>   <int> <int>      <dbl>      <dbl>
#> 1    -2    -1     -3.67      -0.911
#> 2    -1     0     -1.18       1.61 
#> 3     0     1     -0.562      1.87 
#> 4     1     2      0.157      3.45 
#> 5     2     3     -0.823      6.22