A sequence of powers of 2 is generated based on the first value and the
length of the desired sequence. The first value could either be the first
power in the sequence, or it could be the first value of the sequence. The
powers
argument is used to tell the function what the first value is.
Arguments
- from
The starting power or the value of the first number in the sequence. In the case of the latter, this must be value that is 2 raised to an integer power.
- len
The length of the desired sequence.
- powers
Logical. Whether the first argument is the first power to begin the sequence from, or whether it is the value to begin the sequence from.
Details
The function only generates sequences of 2 raised to integer powers. It can be useful in generating breaks values for exponential colour scales.
Examples
# Start from 1
seq_pwr2(0, 5)
#> [1] 1 2 4 8 16
seq_pwr2(1, 5, powers = FALSE)
#> [1] 1 2 4 8 16
# Start from a value larger than 1
seq_pwr2(3, 5)
#> [1] 8 16 32 64 128
seq_pwr2(8, 5, powers = FALSE)
#> [1] 8 16 32 64 128
# Start from a value smaller than 1
seq_pwr2(-3, 5)
#> [1] 0.125 0.250 0.500 1.000 2.000
seq_pwr2(0.125, 5, powers = FALSE)
#> [1] 0.125 0.250 0.500 1.000 2.000