Skip to contents

Convert ratios to colors for maps, heatmap text, or barplots

Usage

ratio2color(
  x,
  colorbins = ejscreen_color_defaults("ratio")$colorbins,
  colorfills = ejscreen_color_defaults("ratio")$colorfills
)

Arguments

x

Numeric vector of ratios to an average (1 means equal to average). Finite ratios above 100 are valid. Missing and nonfinite values return NA.

colorbins

Strictly increasing interior cutoffs, without endpoints.

colorfills

Vector of colors of length length(colorbins) + 1.

Value

Character vector of colors, as long as x.

Details

Cutoffs belong to the higher bin. Values below the first cutoff, including negative values, receive the first color, matching barplots.

Examples

EJAM:::ratio2color(c(1, 1.049, 1.05, 2, 3, 200, NA))
# gray, gray, yellow, orange, red, red, NA
EJAM:::ratio2color(c(1, 2, 4),
  colorbins = c(2, 4), colorfills = c("gray", "orange", "red"))