Color palette for (symmetric) breaks
Given a vector of breaks specifying a set of intervals, this function provides a vector of colors for the indicating the intervals graphically. If the intervals are arranged symmetrically around a specified value, the colors try to reflect this.
breakColors(breaks, colors, center = 0, tol = 0.001)
- a vector of breaks
- either an explicit vector of colors, or a palette function that takes a number and returns a vector of colors
- optional center around which to check for symmetry
- tolerance (as relative error) for deviation from mathematically exact symmetry
The meaning of symmetrical is rather generous here: it is enough that the intervals specified by
breaks are of equal length and that
center is one of the breaks. This means we allow for more or less intervals on one side of
This really only works well if
colors is specified as
g2r.colors, which returns a symmetrical color vector (from green to red) if an even number of colors is requested. The whole point is then that if there are more classes to one side of
center than to the other, this will be reflected by deeper shades of red or green on the appropriate side.
A vector of colors, of length one less than the number of breaks.
## Fully symmetrical breaks br1 = (-3) : 3 co1 = breakColors(br1, g2r.colors) co1 doLegend(br1, co1, 1) ## Truncated on one side br2 = (-2) : 4 co2 = breakColors(br2, g2r.colors) co2 doLegend(br2, co2, 1) ## Does not work with other color schemes co3 = breakColors(br2, heat.colors) co3 doLegend(br2, co3, 1)