Cycle a bounded set of colour indices over the values of a key
Source:R/circular_plotting.R
cycle_colours.RdThe order-stable primitive behind [assign_cycle_colours()] (and so [radiate()]'s `colour_cycle`). Maps each value of `x` to an index in `1:n`, numbering the distinct values by `levels` and wrapping back to `1` after every `n`. Passing an explicit `levels` lets two data frames that share a key (for example tracks and an overlay drawn on top of them) be coloured identically, so a given key value gets the same colour in both.
Value
A factor the same length as `x` with levels `"1"`..`"n"` giving the cycled colour index. `NA` in `x` is preserved as `NA`.
Examples
cycle_colours(c("a", "b", "c", "a"), n = 2)
#> [1] 1 2 1 1
#> Levels: 1 2